Class: Mayu::EncryptedMarshal::Message
- Inherits:
-
Data
- Object
- Data
- Mayu::EncryptedMarshal::Message
- Defined in:
- lib/mayu/encrypted_marshal.rb
Instance Attribute Summary collapse
-
#ad ⇒ Object
readonly
Returns the value of attribute ad.
-
#ciphertext ⇒ Object
readonly
Returns the value of attribute ciphertext.
-
#nonce ⇒ Object
readonly
Returns the value of attribute nonce.
Class Method Summary collapse
Instance Method Summary collapse
- #expired?(now: Time.now) ⇒ Boolean
- #expires_at ⇒ Object
- #pack ⇒ Object
- #verify_timestamps!(now: Time.now) ⇒ Object
Instance Attribute Details
#ad ⇒ Object (readonly)
Returns the value of attribute ad
36 37 38 |
# File 'lib/mayu/encrypted_marshal.rb', line 36 def ad @ad end |
#ciphertext ⇒ Object (readonly)
Returns the value of attribute ciphertext
36 37 38 |
# File 'lib/mayu/encrypted_marshal.rb', line 36 def ciphertext @ciphertext end |
#nonce ⇒ Object (readonly)
Returns the value of attribute nonce
36 37 38 |
# File 'lib/mayu/encrypted_marshal.rb', line 36 def nonce @nonce end |
Class Method Details
.unpack(data) ⇒ Object
38 39 40 41 42 43 |
# File 'lib/mayu/encrypted_marshal.rb', line 38 def self.unpack(data) data.unpack("S a*") => [nonce_length, data] data.unpack("a#{nonce_length} S a*") => [nonce, ad_length, data] data.unpack("a#{ad_length} a*") => [ad, ciphertext] new(nonce, AdditionalData.unpack(ad), ciphertext) end |
Instance Method Details
#expired?(now: Time.now) ⇒ Boolean
56 |
# File 'lib/mayu/encrypted_marshal.rb', line 56 def expired?(now: Time.now) = ad.expired?(now:) |
#expires_at ⇒ Object
57 |
# File 'lib/mayu/encrypted_marshal.rb', line 57 def expires_at = ad.expires_at |
#pack ⇒ Object
45 46 47 48 49 50 51 52 53 54 |
# File 'lib/mayu/encrypted_marshal.rb', line 45 def pack packed_ad = ad.pack [ nonce.bytesize, nonce, packed_ad.bytesize, packed_ad, ciphertext ].pack("S a* S a* a*") end |
#verify_timestamps!(now: Time.now) ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/mayu/encrypted_marshal.rb', line 59 def (now: Time.now) if ad.expired?(now:) raise ExpiredError, "Message expired at #{ad.expires_at}" end if ad.issued_at > now.to_f raise IssuedInTheFutureError, "Message was issued in the future, #{Time.at(ad.issued_at)}" end self end |