Class: Interapp::Message
- Inherits:
-
Object
- Object
- Interapp::Message
- Defined in:
- app/models/interapp/message.rb
Instance Attribute Summary collapse
-
#payload ⇒ Object
Returns the value of attribute payload.
-
#peer ⇒ Object
Returns the value of attribute peer.
-
#signature ⇒ Object
Returns the value of attribute signature.
Instance Method Summary collapse
-
#initialize(attributes = {}) ⇒ Message
constructor
A new instance of Message.
- #sign ⇒ Object
- #signature_decoded ⇒ Object
- #verify ⇒ Object
Constructor Details
#initialize(attributes = {}) ⇒ Message
Returns a new instance of Message.
5 6 7 |
# File 'app/models/interapp/message.rb', line 5 def initialize(attributes = {}) attributes.each { |name, value| send("#{name}=", value) } end |
Instance Attribute Details
#payload ⇒ Object
Returns the value of attribute payload.
3 4 5 |
# File 'app/models/interapp/message.rb', line 3 def payload @payload end |
#peer ⇒ Object
Returns the value of attribute peer.
3 4 5 |
# File 'app/models/interapp/message.rb', line 3 def peer @peer end |
#signature ⇒ Object
Returns the value of attribute signature.
3 4 5 |
# File 'app/models/interapp/message.rb', line 3 def signature @signature end |
Instance Method Details
#sign ⇒ Object
13 14 15 16 |
# File 'app/models/interapp/message.rb', line 13 def sign encoded_signature = Interapp::Cryptography.sign(payload, Interapp.configuration.private_key.to_i(16)) self.signature = encoded_signature.unpack("H*").first end |
#signature_decoded ⇒ Object
18 19 20 |
# File 'app/models/interapp/message.rb', line 18 def signature_decoded ECDSA::Format::SignatureDerString.decode([signature].pack("H*")) end |
#verify ⇒ Object
9 10 11 |
# File 'app/models/interapp/message.rb', line 9 def verify Interapp::Cryptography.verify(payload, signature_decoded, peer.public_key_decoded) end |