Module: Prototok
- Extended by:
- Errors
- Defined in:
- lib/prototok.rb,
lib/prototok/token.rb,
lib/prototok/utils.rb,
lib/prototok/config.rb,
lib/prototok/errors.rb,
lib/prototok/ciphers.rb,
lib/prototok/version.rb,
lib/prototok/encoders.rb,
lib/prototok/attribute.rb,
lib/prototok/ciphers/v1.rb,
lib/prototok/formatters.rb,
lib/prototok/serializers.rb,
lib/prototok/utils/paths.rb,
lib/prototok/utils/listed.rb,
lib/prototok/utils/protoc.rb,
lib/prototok/encoders/json.rb,
lib/prototok/ciphers/V1/mac.rb,
lib/prototok/ciphers/V1/sign.rb,
lib/prototok/encoders/msgpack.rb,
lib/prototok/serializers/time.rb,
lib/prototok/encoders/protobuf.rb,
lib/prototok/serializers/token.rb,
lib/prototok/utils/test_helper.rb,
lib/prototok/formatters/default.rb,
lib/prototok/utils/type_attributes.rb,
lib/prototok/ciphers/V1/encrypted_mac.rb,
lib/prototok/ciphers/V1/encrypted_sign.rb
Defined Under Namespace
Modules: Ciphers, Encoders, Errors, Formatters, Serializers, Utils
Classes: Token
Constant Summary
collapse
- CLAIM_ALIASES =
[
[:exp, %i[expires_at use_before]],
[:nbf, %i[not_before use_after]],
[:iat, [:created_at]],
[:jti, %i[token_id id]],
[:payload, []]
].freeze
- CONFIG_DEFAULTS =
{
formatter: :default,
version: 1,
op: :encrypted_mac,
encoder: :json,
token_delimiter: '.',
encoder_options: {
encoding_mode: :token
},
time_encoding_precision: 10
}.freeze
- VERSION =
"0.1.2"
Constants included
from Errors
Errors::MESSAGES
Class Method Summary
collapse
Methods included from Errors
err
Class Method Details
.configuration ⇒ Object
Also known as:
config
15
16
17
|
# File 'lib/prototok/config.rb', line 15
def configuration
@configutation ||= CONFIG_DEFAULTS.dup
end
|
19
20
21
|
# File 'lib/prototok/config.rb', line 19
def configure
yield(configuration)
end
|
.decode(encoded = nil, *cipher_args, **opts) ⇒ Object
23
24
25
26
27
28
|
# File 'lib/prototok.rb', line 23
def decode(encoded=nil, *cipher_args, **opts)
raise ArgumentError if encoded.nil?
unformatted = formatter(opts[:formatter]).new.decode(encoded)
unprocessed = cipher(**opts).new(*cipher_args).decode(*unformatted)
encoder_instance(**opts).decode(unprocessed)
end
|
.encode(payload = nil, *cipher_args, **opts) ⇒ Object
15
16
17
18
19
20
21
|
# File 'lib/prototok.rb', line 15
def encode(payload=nil, *cipher_args, **opts)
raise ArgumentError if payload.nil?
= opts[:header] || {}
encoded = encoder_instance(**opts).encode(payload, **)
processed = cipher(**opts).new(*cipher_args).encode(encoded)
formatter(opts[:formatter]).new.encode(*processed)
end
|
.key(*args, **opts) ⇒ Object
30
31
32
|
# File 'lib/prototok.rb', line 30
def key(*args, **opts)
cipher(**opts).key(*args)
end
|