Module: JOSE::JWA::Ed25519_CryptoRb
- Extended by:
- Ed25519_CryptoRb
- Included in:
- Ed25519_CryptoRb
- Defined in:
- lib/jose/jwa/ed25519_cryptorb.rb
Instance Method Summary collapse
- #coerce_signing_key!(sk) ⇒ Object
- #coerce_verify_key!(pk) ⇒ Object
- #keypair(secret = nil) ⇒ Object
- #sign(m, sk) ⇒ Object
- #sign_ph(m, sk) ⇒ Object
- #sk_to_pk(sk) ⇒ Object
- #verify(sig, m, pk) ⇒ Object
- #verify_ph(sig, m, pk) ⇒ Object
Instance Method Details
#coerce_signing_key!(sk) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/jose/jwa/ed25519_cryptorb.rb', line 33 def coerce_signing_key!(sk) return sk if sk.is_a?(Ed25519::SigningKey) sk = if not sk.respond_to?(:bytesize) begin JOSE::JWA::Ed25519.coerce_secret_bytes!(sk) rescue ArgumentError JOSE::JWA::Ed25519.coerce_secretkey_bytes!(sk) end else sk end return Ed25519::SigningKey.from_keypair(sk) if sk.bytesize === JOSE::JWA::Ed25519::C_secretkeybytes return Ed25519::SigningKey.new(sk) end |
#coerce_verify_key!(pk) ⇒ Object
49 50 51 52 53 |
# File 'lib/jose/jwa/ed25519_cryptorb.rb', line 49 def coerce_verify_key!(pk) return pk if pk.is_a?(Ed25519::VerifyKey) pk = JOSE::JWA::Ed25519.coerce_publickey_bytes!(pk) if not pk.respond_to?(:bytesize) return Ed25519::VerifyKey.new(pk) end |
#keypair(secret = nil) ⇒ Object
5 6 7 8 9 10 |
# File 'lib/jose/jwa/ed25519_cryptorb.rb', line 5 def keypair(secret = nil) secret ||= Ed25519::SigningKey.generate() sk = coerce_signing_key!(secret) pk = sk.verify_key() return pk.to_bytes(), sk.keypair() end |
#sign(m, sk) ⇒ Object
16 17 18 19 |
# File 'lib/jose/jwa/ed25519_cryptorb.rb', line 16 def sign(m, sk) signing_key = coerce_signing_key!(sk) return signing_key.sign(m) end |
#sign_ph(m, sk) ⇒ Object
21 22 23 |
# File 'lib/jose/jwa/ed25519_cryptorb.rb', line 21 def sign_ph(m, sk) return sign(Digest::SHA512.digest(m), sk) end |
#sk_to_pk(sk) ⇒ Object
12 13 14 |
# File 'lib/jose/jwa/ed25519_cryptorb.rb', line 12 def sk_to_pk(sk) return sk[Ed25519::KEY_SIZE..-1] end |
#verify(sig, m, pk) ⇒ Object
25 26 27 |
# File 'lib/jose/jwa/ed25519_cryptorb.rb', line 25 def verify(sig, m, pk) return Ed25519::VerifyKey.new(pk).verify(sig, m) end |
#verify_ph(sig, m, pk) ⇒ Object
29 30 31 |
# File 'lib/jose/jwa/ed25519_cryptorb.rb', line 29 def verify_ph(sig, m, pk) return verify(sig, Digest::SHA512.digest(m), pk) end |