Module: CaveatEmptor::Serialization
- Defined in:
- lib/caveat_emptor/serialization.rb
Constant Summary collapse
- FORMATS =
{ json: 0x01, msgpack: 0x02 }
Class Method Summary collapse
Class Method Details
.deserialize(macaroon) ⇒ Object
17 18 19 20 21 22 23 |
# File 'lib/caveat_emptor/serialization.rb', line 17 def deserialize(macaroon) raw = Base64.urlsafe_decode64(macaroon) format = raw.getbyte(0) raise "Only JSON format implemented" unless format == FORMATS[:json] payload_bytes = raw.byteslice(1..) decode_json(payload_bytes) end |
.serialize(macaroon, format: :json) ⇒ Object
12 13 14 15 |
# File 'lib/caveat_emptor/serialization.rb', line 12 def serialize(macaroon, format: :json) framed = FORMATS[format].chr + encode_json(macaroon) Base64.urlsafe_encode64(framed, padding: false) end |