Class: OCI::Auth::SessionKeySupplier
- Inherits:
-
Object
- Object
- OCI::Auth::SessionKeySupplier
- Defined in:
- lib/oci/auth/session_key_supplier.rb
Overview
A supplier which can vend a public and private key to be used for signing requests
Constant Summary collapse
- PUBLIC_EXPONENT =
Ruby docs suggest 3, 17 or 65537
65_537
Instance Method Summary collapse
-
#initialize(key_size: 2048) ⇒ SessionKeySupplier
constructor
A new instance of SessionKeySupplier.
-
#key_pair ⇒ Hash
Retrieves a public key and private key.
-
#refresh ⇒ Object
Generates a new public and private key.
Constructor Details
#initialize(key_size: 2048) ⇒ SessionKeySupplier
Returns a new instance of SessionKeySupplier.
11 12 13 14 15 16 |
# File 'lib/oci/auth/session_key_supplier.rb', line 11 def initialize(key_size: 2048) @key_size = key_size @refresh_lock = Mutex.new @private_key = OpenSSL::PKey::RSA.generate(@key_size, PUBLIC_EXPONENT) end |
Instance Method Details
#key_pair ⇒ Hash
Retrieves a public key and private key
20 21 22 23 24 25 26 |
# File 'lib/oci/auth/session_key_supplier.rb', line 20 def key_pair @refresh_lock.lock private_key = @private_key @refresh_lock.unlock { 'private_key': private_key, 'public_key': private_key.public_key } end |
#refresh ⇒ Object
Generates a new public and private key
29 30 31 32 33 34 |
# File 'lib/oci/auth/session_key_supplier.rb', line 29 def refresh @refresh_lock.lock @private_key = OpenSSL::PKey::RSA.generate(@key_size, PUBLIC_EXPONENT) ensure @refresh_lock.unlock if @refresh_lock.locked? && @refresh_lock.owned? end |