Sha256: 57517d6f6bce686d6970635c94d7e60f333ec21af34dc58c77385511133573a5

Contents?: true

Size: 803 Bytes

Versions: 1

Compression:

Stored size: 803 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 << caveat
      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.1 lib/macaroons/serializers/json.rb