Class: BorrowDirect::Encryption
- Inherits:
-
Object
- Object
- BorrowDirect::Encryption
- Defined in:
- lib/borrow_direct/encryption.rb
Overview
Implements Relais’ encryption protocol relais.atlassian.net/wiki/display/ILL/Encryption
value = BorrowDirect::Encryption.new(public_key_string).encode_with_ts(api_key_or_other_data)
Instance Attribute Summary collapse
-
#public_key_str ⇒ Object
readonly
Returns the value of attribute public_key_str.
Instance Method Summary collapse
-
#encode_with_ts(value) ⇒ Object
Will add on timestamp according to Relais protocol, encrypt, and Base64-encode, all per Relais protocol.
-
#initialize(a_public_key) ⇒ Encryption
constructor
A new instance of Encryption.
-
#now_timestamp ⇒ Object
Timestamp formatted how Relais wants it, in UTC.
Constructor Details
#initialize(a_public_key) ⇒ Encryption
Returns a new instance of Encryption.
12 13 14 |
# File 'lib/borrow_direct/encryption.rb', line 12 def initialize(a_public_key) @public_key_str = a_public_key end |
Instance Attribute Details
#public_key_str ⇒ Object (readonly)
Returns the value of attribute public_key_str.
10 11 12 |
# File 'lib/borrow_direct/encryption.rb', line 10 def public_key_str @public_key_str end |
Instance Method Details
#encode_with_ts(value) ⇒ Object
Will add on timestamp according to Relais protocol, encrypt, and Base64-encode, all per Relais protocol.
18 19 20 21 22 23 24 25 26 27 |
# File 'lib/borrow_direct/encryption.rb', line 18 def encode_with_ts(value) # Not sure if this object is thread-safe, so we re-create # each time. public_key = OpenSSL::PKey::RSA.new(self.public_key_str) payload = "#{value}|#{self.}" return Base64.encode64(public_key.public_encrypt(payload)) end |
#now_timestamp ⇒ Object
Timestamp formatted how Relais wants it, in UTC
30 31 32 |
# File 'lib/borrow_direct/encryption.rb', line 30 def Time.now.getutc.strftime("%Y%m%d %H%M%S") end |