Class: Paseto::V2::Public::PublicKey
- Inherits:
-
Object
- Object
- Paseto::V2::Public::PublicKey
- Includes:
- Encoder
- Defined in:
- lib/paseto/public.rb
Overview
public-key used for signing and verifing
Class Method Summary collapse
Instance Method Summary collapse
- #encode64 ⇒ Object
- #encode_hex ⇒ Object
-
#initialize(key) ⇒ PublicKey
constructor
A new instance of PublicKey.
- #verify(token, footer = nil) ⇒ Object
Constructor Details
#initialize(key) ⇒ PublicKey
Returns a new instance of PublicKey.
78 79 80 81 |
# File 'lib/paseto/public.rb', line 78 def initialize(key) @key = key @nacl = RbNaCl::VerifyKey.new(key) end |
Class Method Details
.decode64(encoded_key) ⇒ Object
70 71 72 |
# File 'lib/paseto/public.rb', line 70 def self.decode64(encoded_key) new(Paseto.decode64(encoded_key)) end |
.decode_hex(encoded_key) ⇒ Object
74 75 76 |
# File 'lib/paseto/public.rb', line 74 def self.decode_hex(encoded_key) new(Paseto.decode_hex(encoded_key)) end |
Instance Method Details
#encode64 ⇒ Object
83 84 85 |
# File 'lib/paseto/public.rb', line 83 def encode64 Paseto.encode64(@key) end |
#encode_hex ⇒ Object
87 88 89 |
# File 'lib/paseto/public.rb', line 87 def encode_hex Paseto.encode_hex(@key) end |
#verify(token, footer = nil) ⇒ Object
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/paseto/public.rb', line 91 def verify(token, = nil) ||= token. if token.is_a? Paseto::Token ||= EMPTY_FOOTER parsed = Paseto.verify_token(token, HEADER, ) = parsed.payload[0..-(SIGNATURE_BYTES + 1)] signature = parsed.payload[-SIGNATURE_BYTES..-1] if .nil? || signature.nil? raise BadMessageError, 'Unable to process message' end begin data = (, ) @nacl.verify(signature, data) rescue RbNaCl::BadSignatureError raise AuthenticationError, 'Token signature invalid' end end |