ruby-paseto 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (116) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +8 -0
  3. data/CODE_OF_CONDUCT.md +84 -0
  4. data/LICENSE.txt +21 -0
  5. data/README.md +549 -0
  6. data/lib/paseto/asn1/algorithm_identifier.rb +17 -0
  7. data/lib/paseto/asn1/curve_private_key.rb +22 -0
  8. data/lib/paseto/asn1/ec_private_key.rb +27 -0
  9. data/lib/paseto/asn1/ecdsa_full_r.rb +26 -0
  10. data/lib/paseto/asn1/ecdsa_sig_value.rb +23 -0
  11. data/lib/paseto/asn1/ecdsa_signature.rb +49 -0
  12. data/lib/paseto/asn1/ed25519_identifier.rb +15 -0
  13. data/lib/paseto/asn1/named_curve.rb +17 -0
  14. data/lib/paseto/asn1/one_asymmetric_key.rb +32 -0
  15. data/lib/paseto/asn1/private_key.rb +17 -0
  16. data/lib/paseto/asn1/private_key_algorithm_identifier.rb +17 -0
  17. data/lib/paseto/asn1/public_key.rb +17 -0
  18. data/lib/paseto/asn1/subject_public_key_info.rb +28 -0
  19. data/lib/paseto/asn1.rb +101 -0
  20. data/lib/paseto/asymmetric_key.rb +100 -0
  21. data/lib/paseto/configuration/box.rb +23 -0
  22. data/lib/paseto/configuration/decode_configuration.rb +68 -0
  23. data/lib/paseto/configuration.rb +18 -0
  24. data/lib/paseto/interface/i_d.rb +23 -0
  25. data/lib/paseto/interface/key.rb +113 -0
  26. data/lib/paseto/interface/pbkd.rb +83 -0
  27. data/lib/paseto/interface/pie.rb +59 -0
  28. data/lib/paseto/interface/pke.rb +86 -0
  29. data/lib/paseto/interface/serializer.rb +19 -0
  30. data/lib/paseto/interface/version.rb +161 -0
  31. data/lib/paseto/interface/wrapper.rb +20 -0
  32. data/lib/paseto/operations/i_d.rb +48 -0
  33. data/lib/paseto/operations/id/i_dv3.rb +20 -0
  34. data/lib/paseto/operations/id/i_dv4.rb +20 -0
  35. data/lib/paseto/operations/pbkd/p_b_k_dv3.rb +85 -0
  36. data/lib/paseto/operations/pbkd/p_b_k_dv4.rb +94 -0
  37. data/lib/paseto/operations/pbkw.rb +73 -0
  38. data/lib/paseto/operations/pke/p_k_ev3.rb +97 -0
  39. data/lib/paseto/operations/pke/p_k_ev4.rb +95 -0
  40. data/lib/paseto/operations/pke.rb +57 -0
  41. data/lib/paseto/operations/wrap.rb +29 -0
  42. data/lib/paseto/paserk.rb +55 -0
  43. data/lib/paseto/paserk_types.rb +46 -0
  44. data/lib/paseto/protocol/version3.rb +100 -0
  45. data/lib/paseto/protocol/version4.rb +99 -0
  46. data/lib/paseto/result.rb +9 -0
  47. data/lib/paseto/serializer/optional_json.rb +30 -0
  48. data/lib/paseto/serializer/raw.rb +23 -0
  49. data/lib/paseto/sodium/curve_25519.rb +46 -0
  50. data/lib/paseto/sodium/safe_ed25519_loader.rb +19 -0
  51. data/lib/paseto/sodium/stream/base.rb +82 -0
  52. data/lib/paseto/sodium/stream/x_cha_cha20_xor.rb +31 -0
  53. data/lib/paseto/sodium.rb +5 -0
  54. data/lib/paseto/symmetric_key.rb +119 -0
  55. data/lib/paseto/token.rb +127 -0
  56. data/lib/paseto/token_types.rb +29 -0
  57. data/lib/paseto/util.rb +105 -0
  58. data/lib/paseto/v3/local.rb +63 -0
  59. data/lib/paseto/v3/public.rb +204 -0
  60. data/lib/paseto/v4/local.rb +56 -0
  61. data/lib/paseto/v4/public.rb +169 -0
  62. data/lib/paseto/validator.rb +154 -0
  63. data/lib/paseto/verifiers/footer.rb +30 -0
  64. data/lib/paseto/verifiers/payload.rb +42 -0
  65. data/lib/paseto/verify.rb +48 -0
  66. data/lib/paseto/version.rb +6 -0
  67. data/lib/paseto/versions.rb +25 -0
  68. data/lib/paseto/wrappers/pie/pie_v3.rb +72 -0
  69. data/lib/paseto/wrappers/pie/pie_v4.rb +72 -0
  70. data/lib/paseto/wrappers/pie.rb +71 -0
  71. data/lib/paseto.rb +99 -0
  72. data/paseto.gemspec +58 -0
  73. data/sorbet/config +3 -0
  74. data/sorbet/rbi/annotations/rainbow.rbi +269 -0
  75. data/sorbet/rbi/gems/ast@2.4.2.rbi +584 -0
  76. data/sorbet/rbi/gems/diff-lcs@1.5.0.rbi +1083 -0
  77. data/sorbet/rbi/gems/docile@1.4.0.rbi +376 -0
  78. data/sorbet/rbi/gems/ffi@1.15.5.rbi +1994 -0
  79. data/sorbet/rbi/gems/io-console@0.5.11.rbi +8 -0
  80. data/sorbet/rbi/gems/irb@1.5.1.rbi +342 -0
  81. data/sorbet/rbi/gems/json@2.6.3.rbi +1541 -0
  82. data/sorbet/rbi/gems/multi_json@1.15.0.rbi +267 -0
  83. data/sorbet/rbi/gems/netrc@0.11.0.rbi +158 -0
  84. data/sorbet/rbi/gems/oj@3.13.23.rbi +603 -0
  85. data/sorbet/rbi/gems/openssl@3.0.1.rbi +1735 -0
  86. data/sorbet/rbi/gems/parallel@1.22.1.rbi +277 -0
  87. data/sorbet/rbi/gems/rainbow@3.1.1.rbi +407 -0
  88. data/sorbet/rbi/gems/rake@13.0.6.rbi +3021 -0
  89. data/sorbet/rbi/gems/rbnacl@7.1.1.rbi +3218 -0
  90. data/sorbet/rbi/gems/regexp_parser@2.6.1.rbi +3481 -0
  91. data/sorbet/rbi/gems/reline@0.3.1.rbi +8 -0
  92. data/sorbet/rbi/gems/rexml@3.2.5.rbi +4717 -0
  93. data/sorbet/rbi/gems/rspec-core@3.12.0.rbi +10887 -0
  94. data/sorbet/rbi/gems/rspec-expectations@3.12.0.rbi +8090 -0
  95. data/sorbet/rbi/gems/rspec-mocks@3.12.0.rbi +5300 -0
  96. data/sorbet/rbi/gems/rspec-support@3.12.0.rbi +1617 -0
  97. data/sorbet/rbi/gems/rspec@3.12.0.rbi +88 -0
  98. data/sorbet/rbi/gems/ruby-progressbar@1.11.0.rbi +1239 -0
  99. data/sorbet/rbi/gems/simplecov-html@0.12.3.rbi +219 -0
  100. data/sorbet/rbi/gems/simplecov@0.21.2.rbi +2135 -0
  101. data/sorbet/rbi/gems/simplecov_json_formatter@0.1.4.rbi +8 -0
  102. data/sorbet/rbi/gems/thor@1.2.1.rbi +3956 -0
  103. data/sorbet/rbi/gems/timecop@0.9.6.rbi +350 -0
  104. data/sorbet/rbi/gems/unicode-display_width@2.3.0.rbi +48 -0
  105. data/sorbet/rbi/gems/webrick@1.7.0.rbi +2555 -0
  106. data/sorbet/rbi/gems/yard-sorbet@0.7.0.rbi +391 -0
  107. data/sorbet/rbi/gems/yard@0.9.28.rbi +17816 -0
  108. data/sorbet/rbi/gems/zeitwerk@2.6.6.rbi +950 -0
  109. data/sorbet/rbi/shims/multi_json.rbi +19 -0
  110. data/sorbet/rbi/shims/openssl.rbi +111 -0
  111. data/sorbet/rbi/shims/rbnacl.rbi +65 -0
  112. data/sorbet/rbi/shims/zeitwerk.rbi +6 -0
  113. data/sorbet/rbi/todo.rbi +7 -0
  114. data/sorbet/tapioca/config.yml +30 -0
  115. data/sorbet/tapioca/require.rb +12 -0
  116. metadata +376 -0
@@ -0,0 +1,113 @@
1
+ # encoding: binary
2
+ # typed: true
3
+ # frozen_string_literal: true
4
+
5
+ module Paseto
6
+ module Interface
7
+ class Key
8
+ extend T::Sig
9
+ extend T::Helpers
10
+
11
+ DOMAIN_SEPARATOR_AUTH = "\x81"
12
+ DOMAIN_SEPARATOR_ENCRYPT = "\x80"
13
+
14
+ abstract!
15
+
16
+ sig do
17
+ abstract.params(
18
+ payload: T::Hash[String, T.untyped],
19
+ footer: String,
20
+ implicit_assertion: String,
21
+ options: T.any(String, Integer, Symbol, T::Boolean)
22
+ ).returns(String)
23
+ end
24
+ def encode!(payload, footer: '', implicit_assertion: '', **options); end
25
+
26
+ sig do
27
+ abstract.params(
28
+ payload: String,
29
+ implicit_assertion: String,
30
+ options: T.nilable(T.any(Proc, String, Integer, Symbol, T::Boolean))
31
+ ).returns(Result)
32
+ end
33
+ def decode!(payload, implicit_assertion: '', **options); end
34
+
35
+ sig { abstract.returns(String) }
36
+ def id; end
37
+
38
+ sig { abstract.returns(String) }
39
+ def paserk; end
40
+
41
+ sig { abstract.returns(String) }
42
+ def pbkw_header; end
43
+
44
+ sig { abstract.returns(Version) }
45
+ def protocol; end
46
+
47
+ sig { abstract.returns(String) }
48
+ def purpose; end
49
+
50
+ sig { abstract.returns(String) }
51
+ def to_bytes; end
52
+
53
+ sig(:final) do
54
+ params(
55
+ payload: String,
56
+ implicit_assertion: String,
57
+ options: T.nilable(T.any(Proc, String, Integer, Symbol, T::Boolean))
58
+ ).returns(Result)
59
+ end
60
+ def decode(payload, implicit_assertion: '', **options)
61
+ decode!(payload, **T.unsafe(implicit_assertion: implicit_assertion, **options))
62
+ .then { |result| Verify.verify(result, options) }
63
+ end
64
+
65
+ sig(:final) { returns({ 'exp' => String, 'iat' => String, 'nbf' => String }) }
66
+ def default_claims
67
+ now = Time.new
68
+ {
69
+ 'exp' => (now + (60 * 60)).iso8601,
70
+ 'iat' => now.iso8601,
71
+ 'nbf' => now.iso8601
72
+ }
73
+ end
74
+
75
+ sig(:final) do
76
+ params(
77
+ payload: T::Hash[String, T.untyped],
78
+ footer: T.any(T::Hash[String, T.untyped], String),
79
+ implicit_assertion: String,
80
+ options: T.nilable(T.any(String, Integer, Symbol, T::Boolean))
81
+ ).returns(String)
82
+ end
83
+ def encode(payload, footer: '', implicit_assertion: '', **options)
84
+ footer = MultiJson.dump(footer, mode: :object) if footer.is_a?(Hash)
85
+ default_claims.merge(payload)
86
+ .then { |claims| encode!(claims, footer: footer, implicit_assertion: implicit_assertion, **options) }
87
+ end
88
+
89
+ sig(:final) { params(other: T.untyped).returns(T::Boolean) }
90
+ def ==(other)
91
+ self.class == other.class &&
92
+ to_bytes == other.to_bytes
93
+ end
94
+
95
+ sig(:final) { returns(String) }
96
+ def header = "#{version}.#{purpose}"
97
+
98
+ sig(:final) { returns(String) }
99
+ def paserk_version = protocol.paserk_version
100
+
101
+ sig(:final) { returns(String) }
102
+ def pae_header = "#{header}."
103
+
104
+ sig(:final) { params(password: String, options: T::Hash[Symbol, T.any(Integer, Symbol)]).returns(String) }
105
+ def pbkd(password:, options: {})
106
+ Operations::PBKW.pbkw(self, password, options)
107
+ end
108
+
109
+ sig(:final) { returns(String) }
110
+ def version = protocol.version
111
+ end
112
+ end
113
+ end
@@ -0,0 +1,83 @@
1
+ # typed: strict
2
+ # frozen_string_literal: true
3
+
4
+ module Paseto
5
+ module Interface
6
+ module PBKD
7
+ extend T::Sig
8
+ extend T::Helpers
9
+
10
+ include Kernel
11
+
12
+ abstract!
13
+
14
+ module ClassMethods
15
+ extend T::Sig
16
+ extend T::Helpers
17
+
18
+ interface!
19
+
20
+ sig { abstract.returns(Interface::Version) }
21
+ def protocol; end
22
+ end
23
+
24
+ mixes_in_class_methods(ClassMethods)
25
+
26
+ sig do
27
+ abstract.params(
28
+ header: String,
29
+ pre_key: String,
30
+ salt: String,
31
+ nonce: String,
32
+ edk: String,
33
+ params: T::Hash[Symbol, Integer]
34
+ ).returns([String, String])
35
+ end
36
+ def authenticate(header:, pre_key:, salt:, nonce:, edk:, params:); end # rubocop:disable Metrics/ParameterLists
37
+
38
+ sig(:final) { params(payload: String, key: String, nonce: String).returns(String) }
39
+ def crypt(payload:, key:, nonce:)
40
+ ek = protocol.digest("#{Operations::PBKW::DOMAIN_SEPARATOR_ENCRYPT}#{key}", digest_size: 32)
41
+
42
+ protocol.crypt(key: ek, nonce: nonce, payload: payload)
43
+ end
44
+
45
+ sig do
46
+ abstract.params(payload: String).returns(
47
+ {
48
+ salt: String,
49
+ nonce: String,
50
+ edk: String,
51
+ tag: String,
52
+ params: T::Hash[Symbol, Integer]
53
+ }
54
+ )
55
+ end
56
+ def decode(payload); end
57
+
58
+ sig { abstract.params(salt: String, params: T::Hash[Symbol, Integer]).returns(String) }
59
+ def pre_key(salt:, params:); end
60
+
61
+ sig(:final) { returns(String) }
62
+ def paserk_version
63
+ protocol.paserk_version
64
+ end
65
+
66
+ sig(:final) { returns(Interface::Version) }
67
+ def protocol
68
+ self.class.protocol
69
+ end
70
+
71
+ sig { abstract.returns(String) }
72
+ def random_nonce; end
73
+
74
+ sig { abstract.returns(String) }
75
+ def random_salt; end
76
+
77
+ sig(:final) { returns(String) }
78
+ def version
79
+ protocol.version
80
+ end
81
+ end
82
+ end
83
+ end
@@ -0,0 +1,59 @@
1
+ # encoding: binary
2
+ # typed: strict
3
+ # frozen_string_literal: true
4
+
5
+ module Paseto
6
+ module Interface
7
+ module PIE
8
+ extend T::Sig
9
+ extend T::Helpers
10
+
11
+ include Kernel
12
+
13
+ abstract!
14
+
15
+ module ClassMethods
16
+ extend T::Sig
17
+ extend T::Helpers
18
+
19
+ interface!
20
+
21
+ sig { abstract.params(data: String).returns({ t: String, n: String, c: String }) }
22
+ def decode_and_split(data); end
23
+
24
+ sig { abstract.returns(Interface::Version) }
25
+ def protocol; end
26
+ end
27
+
28
+ mixes_in_class_methods(ClassMethods)
29
+
30
+ sig { abstract.params(nonce: String).returns(String) }
31
+ def authentication_key(nonce:); end
32
+
33
+ sig { abstract.params(payload: String, auth_key: String).returns(String) }
34
+ def authentication_tag(payload:, auth_key:); end
35
+
36
+ sig { abstract.params(nonce: String, payload: String).returns(String) }
37
+ def crypt(nonce:, payload:); end
38
+
39
+ sig { params(data: String).returns({ t: String, n: String, c: String }) }
40
+ def decode_and_split(data)
41
+ self.class.decode_and_split(data)
42
+ end
43
+
44
+ sig { abstract.returns(String) }
45
+ def local_header; end
46
+
47
+ sig { abstract.returns(String) }
48
+ def random_nonce; end
49
+
50
+ sig { abstract.returns(String) }
51
+ def secret_header; end
52
+
53
+ sig(:final) { returns(Interface::Version) }
54
+ def protocol
55
+ self.class.protocol
56
+ end
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,86 @@
1
+ # encoding: binary
2
+ # typed: strict
3
+ # frozen_string_literal: true
4
+
5
+ module Paseto
6
+ module Interface
7
+ module PKE
8
+ extend T::Sig
9
+ extend T::Helpers
10
+
11
+ include Kernel
12
+
13
+ abstract!
14
+
15
+ DOMAIN_SEPARATOR_ENCRYPT = "\x01"
16
+ DOMAIN_SEPARATOR_AUTH = "\x02"
17
+
18
+ module ClassMethods
19
+ extend T::Sig
20
+ extend T::Helpers
21
+
22
+ interface!
23
+
24
+ sig { abstract.params(esk: T.untyped).returns(String) }
25
+ def epk_bytes_from_esk(esk); end
26
+
27
+ sig { abstract.returns(T.untyped) }
28
+ def generate_ephemeral_key; end
29
+
30
+ sig { abstract.returns(String) }
31
+ def header; end
32
+
33
+ sig { abstract.returns(Interface::Version) }
34
+ def protocol; end
35
+
36
+ sig { abstract.params(encoded_data: String).returns([String, T.untyped, String]) }
37
+ def split(encoded_data); end
38
+ end
39
+
40
+ mixes_in_class_methods(ClassMethods)
41
+
42
+ sig { abstract.returns(AsymmetricKey) }
43
+ def sealing_key; end
44
+
45
+ sig { abstract.params(xk: String, epk: T.untyped).returns(String) }
46
+ def derive_ak(xk:, epk:); end
47
+
48
+ sig { abstract.params(xk: String, epk: T.untyped).returns({ ek: String, n: String }) }
49
+ def derive_ek_n(xk:, epk:); end
50
+
51
+ sig { abstract.params(message: String, ek: String, n: String).returns(SymmetricKey) }
52
+ def decrypt(message:, ek:, n:); end
53
+
54
+ sig { abstract.params(message: String, ek: String, n: String).returns(String) }
55
+ def encrypt(message:, ek:, n:); end
56
+
57
+ sig { abstract.params(ak: String, epk: T.untyped, edk: String).returns(String) }
58
+ def tag(ak:, epk:, edk:); end
59
+
60
+ sig(:final) { params(esk: T.untyped).returns(String) }
61
+ def epk_bytes_from_esk(esk)
62
+ self.class.epk_bytes_from_esk(esk)
63
+ end
64
+
65
+ sig(:final) { returns(T.untyped) }
66
+ def generate_ephemeral_key
67
+ self.class.generate_ephemeral_key
68
+ end
69
+
70
+ sig(:final) { returns(String) }
71
+ def header
72
+ self.class.header
73
+ end
74
+
75
+ sig(:final) { returns(Interface::Version) }
76
+ def protocol
77
+ self.class.protocol
78
+ end
79
+
80
+ sig(:final) { params(encoded_data: String).returns([String, T.untyped, String]) }
81
+ def split(encoded_data)
82
+ self.class.split(encoded_data)
83
+ end
84
+ end
85
+ end
86
+ end
@@ -0,0 +1,19 @@
1
+ # typed: strict
2
+ # frozen_string_literal: true
3
+
4
+ module Paseto
5
+ module Interface
6
+ module Serializer
7
+ extend T::Sig
8
+ extend T::Helpers
9
+
10
+ interface!
11
+
12
+ sig { abstract.params(val: String, options: T::Hash[T.untyped, T.untyped]).returns(T.untyped) }
13
+ def deserialize(val, options); end
14
+
15
+ sig { abstract.params(val: T.untyped, options: T::Hash[T.untyped, T.untyped]).returns(String) }
16
+ def serialize(val, options); end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,161 @@
1
+ # typed: strict
2
+ # frozen_string_literal: true
3
+
4
+ module Paseto
5
+ module Interface
6
+ module Version
7
+ extend T::Sig
8
+ extend T::Helpers
9
+
10
+ include Comparable
11
+ include Kernel
12
+
13
+ abstract!
14
+
15
+ module ClassMethods
16
+ extend T::Sig
17
+ extend T::Helpers
18
+
19
+ interface!
20
+
21
+ sig { abstract.params(key: String, nonce: String, payload: String).returns(String) }
22
+ def crypt(key:, nonce:, payload:); end
23
+
24
+ sig { abstract.params(data: String, digest_size: Integer).returns(String) }
25
+ def digest(data, digest_size:); end
26
+
27
+ sig { abstract.returns(Integer) }
28
+ def digest_bytes; end
29
+
30
+ sig { abstract.params(data: String, key: String, digest_size: Integer).returns(String) }
31
+ def hmac(data, key:, digest_size:); end
32
+
33
+ sig { abstract.returns(Interface::ID) }
34
+ def id; end
35
+
36
+ sig do
37
+ abstract.params(
38
+ password: String,
39
+ salt: String,
40
+ length: Integer,
41
+ parameters: Integer
42
+ ).returns(String)
43
+ end
44
+ def kdf(password, salt:, length:, **parameters); end
45
+
46
+ sig { abstract.returns(String) }
47
+ def paserk_version; end
48
+
49
+ sig { abstract.returns(String) }
50
+ def pbkd_local_header; end
51
+
52
+ sig { abstract.returns(String) }
53
+ def pbkd_secret_header; end
54
+
55
+ sig { abstract.params(password: String).returns(Interface::PBKD) }
56
+ def pbkw(password); end
57
+
58
+ sig { abstract.params(key: SymmetricKey).returns(Interface::PIE) }
59
+ def pie(key); end
60
+
61
+ sig { abstract.params(key: AsymmetricKey).returns(Interface::PKE) }
62
+ def pke(key); end
63
+
64
+ sig { abstract.params(size: Integer).returns(String) }
65
+ def random(size); end
66
+
67
+ sig { abstract.returns(String) }
68
+ def version; end
69
+ end
70
+
71
+ mixes_in_class_methods(ClassMethods)
72
+
73
+ sig(:final) { params(key: String, nonce: String, payload: String).returns(String) }
74
+ def crypt(key:, nonce:, payload:)
75
+ self.class.crypt(key: key, nonce: nonce, payload: payload)
76
+ end
77
+
78
+ sig(:final) { params(data: String, digest_size: T.nilable(Integer)).returns(String) }
79
+ def digest(data, digest_size: nil)
80
+ self.class.digest(data, digest_size: digest_size || digest_bytes)
81
+ end
82
+
83
+ sig(:final) { returns(Integer) }
84
+ def digest_bytes
85
+ self.class.digest_bytes
86
+ end
87
+
88
+ sig(:final) { params(data: String, key: String, digest_size: T.nilable(Integer)).returns(String) }
89
+ def hmac(data, key:, digest_size: nil)
90
+ self.class.hmac(data, key: key, digest_size: digest_size || digest_bytes)
91
+ end
92
+
93
+ sig(:final) { returns(Interface::ID) }
94
+ def id
95
+ self.class.id
96
+ end
97
+
98
+ sig(:final) do
99
+ params(
100
+ password: String,
101
+ salt: String,
102
+ length: Integer,
103
+ parameters: T.any(Symbol, Integer)
104
+ ).returns(String)
105
+ end
106
+ def kdf(password, salt:, length:, **parameters)
107
+ self.class.kdf(password, salt: salt, length: length, **parameters)
108
+ end
109
+
110
+ sig(:final) { returns(String) }
111
+ def paserk_version
112
+ self.class.paserk_version
113
+ end
114
+
115
+ sig(:final) { returns(String) }
116
+ def pbkd_local_header
117
+ self.class.pbkd_local_header
118
+ end
119
+
120
+ sig(:final) { returns(String) }
121
+ def pbkd_secret_header
122
+ self.class.pbkd_secret_header
123
+ end
124
+
125
+ sig(:final) { params(password: String).returns(Interface::PBKD) }
126
+ def pbkw(password)
127
+ self.class.pbkw(password)
128
+ end
129
+
130
+ sig(:final) { params(key: SymmetricKey).returns(Interface::PIE) }
131
+ def pie(key)
132
+ self.class.pie(key)
133
+ end
134
+
135
+ sig(:final) { params(key: AsymmetricKey).returns(Interface::PKE) }
136
+ def pke(key)
137
+ self.class.pke(key)
138
+ end
139
+
140
+ sig(:final) { params(size: Integer).returns(String) }
141
+ def random(size)
142
+ self.class.random(size)
143
+ end
144
+
145
+ sig(:final) { returns(String) }
146
+ def version
147
+ self.class.version
148
+ end
149
+
150
+ sig(:final) { params(other: T.untyped).returns(T.nilable(Integer)) }
151
+ def <=>(other)
152
+ case other
153
+ in Interface::Version
154
+ version <=> other.version
155
+ else
156
+ nil
157
+ end
158
+ end
159
+ end
160
+ end
161
+ end
@@ -0,0 +1,20 @@
1
+ # encoding: binary
2
+ # typed: strict
3
+ # frozen_string_literal: true
4
+
5
+ module Paseto
6
+ module Interface
7
+ module Wrapper
8
+ extend T::Sig
9
+ extend T::Helpers
10
+
11
+ interface!
12
+
13
+ sig { abstract.params(key: Key, nonce: T.nilable(String)).returns(String) }
14
+ def encode(key, nonce: nil); end
15
+
16
+ sig { abstract.params(paserk: [String, String, String, String]).returns(Key) }
17
+ def decode(paserk); end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,48 @@
1
+ # encoding: binary
2
+ # typed: strict
3
+ # frozen_string_literal: true
4
+
5
+ module Paseto
6
+ module Operations
7
+ class ID
8
+ extend T::Sig
9
+
10
+ sig(:final) { params(key: SymmetricKey).returns(String) }
11
+ def self.lid(key)
12
+ new(key.protocol).lid(key)
13
+ end
14
+
15
+ sig(:final) { params(key: AsymmetricKey).returns(String) }
16
+ def self.sid(key)
17
+ new(key.protocol).sid(key)
18
+ end
19
+
20
+ sig(:final) { params(key: AsymmetricKey).returns(String) }
21
+ def self.pid(key)
22
+ new(key.protocol).pid(key)
23
+ end
24
+
25
+ sig { params(protocol: Interface::Version).void }
26
+ def initialize(protocol)
27
+ @coder = T.let(protocol.id, Interface::ID)
28
+ end
29
+
30
+ sig(:final) { params(key: SymmetricKey).returns(String) }
31
+ def lid(key)
32
+ @coder.encode('lid', key.paserk)
33
+ end
34
+
35
+ sig(:final) { params(key: AsymmetricKey).returns(String) }
36
+ def sid(key)
37
+ raise ArgumentError, 'no private key available' unless key.private?
38
+
39
+ @coder.encode('sid', key.paserk)
40
+ end
41
+
42
+ sig(:final) { params(key: AsymmetricKey).returns(String) }
43
+ def pid(key)
44
+ @coder.encode('pid', key.public_paserk)
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,20 @@
1
+ # encoding: binary
2
+ # typed: strict
3
+ # frozen_string_literal: true
4
+
5
+ module Paseto
6
+ module Operations
7
+ class ID
8
+ module IDv3
9
+ extend T::Sig
10
+
11
+ extend Interface::ID
12
+
13
+ sig { override.returns(Protocol::Version3) }
14
+ def self.protocol
15
+ Protocol::Version3.new
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,20 @@
1
+ # encoding: binary
2
+ # typed: strict
3
+ # frozen_string_literal: true
4
+
5
+ module Paseto
6
+ module Operations
7
+ class ID
8
+ module IDv4
9
+ extend T::Sig
10
+
11
+ extend Interface::ID
12
+
13
+ sig { override.returns(Protocol::Version4) }
14
+ def self.protocol
15
+ Protocol::Version4.new
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end