|
14 | 14 |
|
15 | 15 | part of 'impl_ffi.dart';
|
16 | 16 |
|
17 |
| -abstract class _Hash implements Hash { |
18 |
| - const _Hash(); |
| 17 | +abstract class _HashImpl implements HashImpl { |
| 18 | + const _HashImpl(); |
19 | 19 |
|
20 |
| - factory _Hash.fromHash(Hash hash) { |
21 |
| - if (hash is _Hash) { |
| 20 | + factory _HashImpl.fromHash(HashImpl hash) { |
| 21 | + if (hash is _HashImpl) { |
22 | 22 | return hash;
|
23 | 23 | }
|
24 |
| - throw ArgumentError.value( |
25 |
| - hash, |
26 |
| - 'hash', |
27 |
| - 'Custom implementations of Hash is not supported', |
28 |
| - ); |
| 24 | + throw AssertionError( |
| 25 | + 'Custom implementations of HashImpl are not supported.'); |
29 | 26 | }
|
30 | 27 |
|
31 | 28 | @protected
|
@@ -62,39 +59,127 @@ abstract class _Hash implements Hash {
|
62 | 59 | return out.copy(size);
|
63 | 60 | });
|
64 | 61 | }
|
| 62 | + |
| 63 | + /// Algorithm (`alg` for JWK) when this hash algorithm is used in an HMAC. |
| 64 | + /// |
| 65 | + /// For SHA-1, it returns 'HS1'. |
| 66 | + /// For SHA-256, it returns 'HS256'. |
| 67 | + /// For SHA-384, it returns 'HS384'. |
| 68 | + /// For SHA-512, it returns 'HS512'. |
| 69 | + /// |
| 70 | + /// See canonical registry in: |
| 71 | + /// https://www.iana.org/assignments/jose/jose.xhtml |
| 72 | + String get hmacJwkAlg; |
| 73 | + |
| 74 | + /// Algorithm (`alg` for JWK) when this hash algorithm is used in RSA-OAEP. |
| 75 | + /// |
| 76 | + /// For SHA-1, it returns 'RSA-OAEP-1'. |
| 77 | + /// For SHA-256, it returns 'RSA-OAEP-256'. |
| 78 | + /// For SHA-384, it returns 'RSA-OAEP-384'. |
| 79 | + /// For SHA-512, it returns 'RSA-OAEP-512'. |
| 80 | + /// |
| 81 | + /// See canonical registry in: |
| 82 | + /// https://www.iana.org/assignments/jose/jose.xhtml |
| 83 | + String get rsaOaepJwkAlg; |
| 84 | + |
| 85 | + /// Algorithm (`alg` for JWK) when this hash algorithm is used in RSA-PSS. |
| 86 | + /// |
| 87 | + /// For SHA-1, it returns 'PS1'. |
| 88 | + /// For SHA-256, it returns 'PS256'. |
| 89 | + /// For SHA-384, it returns 'PS384'. |
| 90 | + /// For SHA-512, it returns 'PS512'. |
| 91 | + /// |
| 92 | + /// See canonical registry in: |
| 93 | + /// https://www.iana.org/assignments/jose/jose.xhtml |
| 94 | + String get rsaPssJwkAlg; |
| 95 | + |
| 96 | + /// Algorithm (`alg` for JWK) when this hash algorithm is used in RSASSA-PKCS1-v1_5. |
| 97 | + /// |
| 98 | + /// For SHA-1, it returns 'RS1'. |
| 99 | + /// For SHA-256, it returns 'RS256'. |
| 100 | + /// For SHA-384, it returns 'RS384'. |
| 101 | + /// For SHA-512, it returns 'RS512'. |
| 102 | + /// |
| 103 | + /// See canonical registry in: |
| 104 | + /// https://www.iana.org/assignments/jose/jose.xhtml |
| 105 | + String get rsassaPkcs1V15JwkAlg; |
65 | 106 | }
|
66 | 107 |
|
67 |
| -class _Sha1 extends _Hash { |
| 108 | +final class _Sha1 extends _HashImpl { |
68 | 109 | const _Sha1();
|
69 | 110 |
|
| 111 | + @override |
| 112 | + String get hmacJwkAlg => 'HS1'; |
| 113 | + |
| 114 | + @override |
| 115 | + String get rsaOaepJwkAlg => 'RSA-OAEP-1'; |
| 116 | + |
| 117 | + @override |
| 118 | + String get rsaPssJwkAlg => 'PS1'; |
| 119 | + |
| 120 | + @override |
| 121 | + String get rsassaPkcs1V15JwkAlg => 'RS1'; |
| 122 | + |
70 | 123 | @override
|
71 | 124 | ffi.Pointer<EVP_MD> Function() get _algorithm => ssl.EVP_sha1;
|
72 | 125 | }
|
73 | 126 |
|
74 |
| -class _Sha256 extends _Hash { |
| 127 | +final class _Sha256 extends _HashImpl { |
75 | 128 | const _Sha256();
|
76 | 129 |
|
| 130 | + @override |
| 131 | + String get hmacJwkAlg => 'HS256'; |
| 132 | + |
| 133 | + @override |
| 134 | + String get rsaOaepJwkAlg => 'RSA-OAEP-256'; |
| 135 | + |
| 136 | + @override |
| 137 | + String get rsaPssJwkAlg => 'PS256'; |
| 138 | + |
| 139 | + @override |
| 140 | + String get rsassaPkcs1V15JwkAlg => 'RS256'; |
| 141 | + |
77 | 142 | @override
|
78 | 143 | ffi.Pointer<EVP_MD> Function() get _algorithm => ssl.EVP_sha256;
|
79 | 144 | }
|
80 | 145 |
|
81 |
| -class _Sha384 extends _Hash { |
| 146 | +final class _Sha384 extends _HashImpl { |
82 | 147 | const _Sha384();
|
83 | 148 |
|
| 149 | + @override |
| 150 | + String get hmacJwkAlg => 'HS384'; |
| 151 | + |
| 152 | + @override |
| 153 | + String get rsaOaepJwkAlg => 'RSA-OAEP-384'; |
| 154 | + |
| 155 | + @override |
| 156 | + String get rsaPssJwkAlg => 'PS384'; |
| 157 | + |
| 158 | + @override |
| 159 | + String get rsassaPkcs1V15JwkAlg => 'RS384'; |
| 160 | + |
84 | 161 | @override
|
85 | 162 | ffi.Pointer<EVP_MD> Function() get _algorithm => ssl.EVP_sha384;
|
86 | 163 | }
|
87 | 164 |
|
88 |
| -class _Sha512 extends _Hash { |
| 165 | +final class _Sha512 extends _HashImpl { |
89 | 166 | const _Sha512();
|
90 | 167 |
|
| 168 | + @override |
| 169 | + String get hmacJwkAlg => 'HS512'; |
| 170 | + |
| 171 | + @override |
| 172 | + String get rsaOaepJwkAlg => 'RSA-OAEP-512'; |
| 173 | + |
| 174 | + @override |
| 175 | + String get rsaPssJwkAlg => 'PS512'; |
| 176 | + |
| 177 | + @override |
| 178 | + String get rsassaPkcs1V15JwkAlg => 'RS512'; |
| 179 | + |
91 | 180 | @override
|
92 | 181 | ffi.Pointer<EVP_MD> Function() get _algorithm => ssl.EVP_sha512;
|
93 | 182 | }
|
94 | 183 |
|
95 |
| -const Hash sha1 = _Sha1(); |
96 |
| -const Hash sha256 = _Sha256(); |
97 |
| -const Hash sha384 = _Sha384(); |
98 |
| -const Hash sha512 = _Sha512(); |
99 | 184 | // Note: Before adding new hash implementations, make sure to update all the
|
100 |
| -// places that does if (hash == Hash.shaXXX) ... |
| 185 | +// places that does if (hash == HashImpl.shaXXX) ... |
0 commit comments