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
-
#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.
66 67 68 69 |
# File 'lib/paseto/public.rb', line 66 def initialize(key) @key = key @nacl = RbNaCl::VerifyKey.new(key) end |
Class Method Details
Instance Method Details
#encode64 ⇒ Object
71 72 73 |
# File 'lib/paseto/public.rb', line 71 def encode64 Paseto.encode64(@key) end |
#verify(token, footer = nil) ⇒ Object
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/paseto/public.rb', line 75 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 |