Sha256: 0dc86bef495c2264bf46dc7f1807d81828e5900f6350c0ad28d01a35e3ab5756

Contents?: true

Size: 798 Bytes

Versions: 1

Compression:

Stored size: 798 Bytes

Contents

require 'json'

module Macaroons
  class JsonSerializer

    def serialize(macaroon)
        serialized = {
          location: macaroon.location,
          identifier: macaroon.identifier,
          caveats: macaroon.caveats.map!(&:to_h),
          signature: macaroon.signature
        }
        return serialized.to_json
    end

    def deserialize(serialized)
      deserialized = JSON.parse(serialized)
      macaroon = Macaroons::RawMacaroon.new(key: 'no_key', identifier: deserialized['identifier'], location: deserialized['location'])
      deserialized['caveats'].each do |c|
        caveat = Macaroons::Caveat.new(c['cid'], c['vid'], c['cl'])
        macaroon.caveats << c
      end
      macaroon.signature = Utils.unhexlify(deserialized['signature'])
      macaroon
    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
macaroons-0.4.0 lib/macaroons/serializers/json.rb