Class: Nuntius::Messenger
- Inherits:
-
Object
- Object
- Nuntius::Messenger
- Defined in:
- lib/nuntius/messenger.rb
Instance Attribute Summary collapse
-
#key ⇒ Object
Returns the value of attribute key.
Instance Method Summary collapse
-
#initialize(attributes) ⇒ Messenger
constructor
A new instance of Messenger.
- #unwrap(options) ⇒ Object
- #wrap(options) ⇒ Object
Constructor Details
#initialize(attributes) ⇒ Messenger
Returns a new instance of Messenger.
5 6 7 |
# File 'lib/nuntius/messenger.rb', line 5 def initialize(attributes) self.key = attributes[:key] end |
Instance Attribute Details
#key ⇒ Object
Returns the value of attribute key.
3 4 5 |
# File 'lib/nuntius/messenger.rb', line 3 def key @key end |
Instance Method Details
#unwrap(options) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/nuntius/messenger.rb', line 23 def unwrap() data = [:envelope].raw_data signature = [:envelope].raw_signature [:from].validate(data, signature) key = @key.decrypt [:envelope].raw_key cipher = OpenSSL::Cipher.new('AES-256-CBC').decrypt cipher.key = key cipher.update(data) + cipher.final end |
#wrap(options) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/nuntius/messenger.rb', line 9 def wrap() cipher = OpenSSL::Cipher.new('AES-256-CBC').encrypt key = [:to].encrypt( cipher.random_key ) data = cipher.update( [:message] ) + cipher.final signature = @key.sign(data) Envelope.new({ :raw_data => data, :raw_key => key, :raw_signature => signature }) end |