Class: OpenSesame::Message
- Inherits:
-
Object
- Object
- OpenSesame::Message
- Defined in:
- lib/open-sesame.rb
Overview
Used for passing messages that cannot be altered. This is not for hiding a message from observers. The message is cryptographically signed but it is not encrypted.
Constant Summary collapse
- @@default_secret =
"OPEN SESAME"
Class Method Summary collapse
-
.generate(message, secret = @@default_secret) ⇒ Object
Generate a message string that can be verified by another computer that knows the shared secret.
-
.message(message, secret = @@default_secret) ⇒ Object
Verify a message that was generated with OpenSesame and return just the message part.
-
.verify(message, secret = @@default_secret) ⇒ Object
Verify that the message has not been altered.
Class Method Details
.generate(message, secret = @@default_secret) ⇒ Object
Generate a message string that can be verified by another computer that knows the shared secret.
47 48 49 50 |
# File 'lib/open-sesame.rb', line 47 def self.generate(, secret = @@default_secret) hash = (Digest::SHA1.new << secret + ).to_s + '-' + hash end |
.message(message, secret = @@default_secret) ⇒ Object
Verify a message that was generated with OpenSesame and return just the message part. Returns nil if the message does not verify.
67 68 69 70 71 72 73 |
# File 'lib/open-sesame.rb', line 67 def self.(, secret = @@default_secret) if self.verify(, secret) (.split /-/).first else nil end end |
.verify(message, secret = @@default_secret) ⇒ Object
Verify that the message has not been altered.
56 57 58 59 |
# File 'lib/open-sesame.rb', line 56 def self.verify(, secret = @@default_secret) string = .split /-/ .eql? generate(string.first, secret) end |