@@ -103,8 +103,8 @@ public:
103
103
virtual kj::Array<kj::byte> exportKeyExt (
104
104
kj::StringPtr format,
105
105
kj::StringPtr type,
106
- jsg::Optional<kj::String> cipher = nullptr ,
107
- jsg::Optional<kj::Array<kj::byte>> passphrase = nullptr ) const override final {
106
+ jsg::Optional<kj::String> cipher = kj::none ,
107
+ jsg::Optional<kj::Array<kj::byte>> passphrase = kj::none ) const override final {
108
108
KJ_REQUIRE (isExtractable (), " Key is not extractable." );
109
109
MarkPopErrorOnReturn mark_pop_error_on_return;
110
110
KJ_REQUIRE (format != " jwk" , " jwk export not supported for exportKeyExt" );
@@ -119,13 +119,13 @@ public:
119
119
120
120
const auto getEncDetail = [&] {
121
121
EncDetail detail;
122
- KJ_IF_MAYBE (pw, passphrase) {
123
- detail.pass = reinterpret_cast <char *>(pw-> begin ());
124
- detail.pass_len = pw-> size ();
122
+ KJ_IF_SOME (pw, passphrase) {
123
+ detail.pass = reinterpret_cast <char *>(pw. begin ());
124
+ detail.pass_len = pw. size ();
125
125
}
126
- KJ_IF_MAYBE (ciph, cipher) {
127
- detail.cipher = EVP_get_cipherbyname (ciph-> cStr ());
128
- JSG_REQUIRE (detail.cipher != nullptr , TypeError, " Unknown cipher " , * ciph);
126
+ KJ_IF_SOME (ciph, cipher) {
127
+ detail.cipher = EVP_get_cipherbyname (ciph. cStr ());
128
+ JSG_REQUIRE (detail.cipher != nullptr , TypeError, " Unknown cipher " , ciph);
129
129
KJ_REQUIRE (detail.pass != nullptr );
130
130
}
131
131
return detail;
@@ -332,11 +332,11 @@ public:
332
332
333
333
bool equals (const CryptoKey::Impl& other) const override final {
334
334
if (this == &other) return true ;
335
- KJ_IF_MAYBE (otherImpl, kj::dynamicDowncastIfAvailable<const AsymmetricKey>(other)) {
335
+ KJ_IF_SOME (otherImpl, kj::dynamicDowncastIfAvailable<const AsymmetricKey>(other)) {
336
336
// EVP_PKEY_cmp will return 1 if the inputs match, 0 if they don't match,
337
337
// -1 if the key types are different, and -2 if the operation is not supported.
338
338
// We only really care about the first two cases.
339
- return EVP_PKEY_cmp (keyData.get (), otherImpl-> keyData .get ()) == 1 ;
339
+ return EVP_PKEY_cmp (keyData.get (), otherImpl. keyData .get ()) == 1 ;
340
340
}
341
341
return false ;
342
342
}
@@ -376,7 +376,7 @@ ImportAsymmetricResult importAsymmetric(jsg::Lock& js, kj::StringPtr format,
376
376
DOMDataError, " JSON Web Key import requires a JSON Web Key object." );
377
377
378
378
kj::StringPtr keyType;
379
- if (keyDataJwk.d != nullptr ) {
379
+ if (keyDataJwk.d != kj::none ) {
380
380
// Private key (`d` is the private exponent, per RFC 7518).
381
381
keyType = " private" ;
382
382
usages =
@@ -385,7 +385,7 @@ ImportAsymmetricResult importAsymmetric(jsg::Lock& js, kj::StringPtr format,
385
385
386
386
// https://tools.ietf.org/html/rfc7518#section-6.3.2.7
387
387
// We don't support keys with > 2 primes, so error out.
388
- JSG_REQUIRE (keyDataJwk.oth == nullptr , DOMNotSupportedError,
388
+ JSG_REQUIRE (keyDataJwk.oth == kj::none , DOMNotSupportedError,
389
389
" Multi-prime private keys not supported." );
390
390
} else {
391
391
// Public key.
@@ -411,32 +411,32 @@ ImportAsymmetricResult importAsymmetric(jsg::Lock& js, kj::StringPtr format,
411
411
}();
412
412
413
413
if (keyUsages.size () > 0 ) {
414
- KJ_IF_MAYBE (use, keyDataJwk.use ) {
415
- JSG_REQUIRE (* use == expectedUse, DOMDataError,
414
+ KJ_IF_SOME (use, keyDataJwk.use ) {
415
+ JSG_REQUIRE (use == expectedUse, DOMDataError,
416
416
" Asymmetric \" jwk\" key import with usages requires a JSON Web Key with "
417
- " Public Key Use parameter \" use\" (\" " , * use, " \" ) equal to \" sig\" ." );
417
+ " Public Key Use parameter \" use\" (\" " , use, " \" ) equal to \" sig\" ." );
418
418
}
419
419
}
420
420
421
- KJ_IF_MAYBE (ops, keyDataJwk.key_ops ) {
421
+ KJ_IF_SOME (ops, keyDataJwk.key_ops ) {
422
422
// TODO(cleanup): When we implement other JWK import functions, factor this part out into a
423
423
// JWK validation function.
424
424
425
425
// "The key operation values are case-sensitive strings. Duplicate key operation values MUST
426
426
// NOT be present in the array." -- RFC 7517, section 4.3
427
- std::sort (ops-> begin (), ops-> end ());
428
- JSG_REQUIRE (std::adjacent_find (ops-> begin (), ops-> end ()) == ops-> end (), DOMDataError,
427
+ std::sort (ops. begin (), ops. end ());
428
+ JSG_REQUIRE (std::adjacent_find (ops. begin (), ops. end ()) == ops. end (), DOMDataError,
429
429
" A JSON Web Key's Key Operations parameter (\" key_ops\" ) "
430
430
" must not contain duplicates." );
431
431
432
- KJ_IF_MAYBE (use, keyDataJwk.use ) {
432
+ KJ_IF_SOME (use, keyDataJwk.use ) {
433
433
// "The "use" and "key_ops" JWK members SHOULD NOT be used together; however, if both are
434
434
// used, the information they convey MUST be consistent." -- RFC 7517, section 4.3.
435
435
436
- JSG_REQUIRE (* use == expectedUse, DOMDataError, " Asymmetric \" jwk\" import requires a JSON "
437
- " Web Key with Public Key Use \" use\" (\" " , * use, " \" ) equal to \" " , expectedUse, " \" ." );
436
+ JSG_REQUIRE (use == expectedUse, DOMDataError, " Asymmetric \" jwk\" import requires a JSON "
437
+ " Web Key with Public Key Use \" use\" (\" " , use, " \" ) equal to \" " , expectedUse, " \" ." );
438
438
439
- for (const auto & op: * ops) {
439
+ for (const auto & op: ops) {
440
440
JSG_REQUIRE (normalizedName != " ECDH" && normalizedName != " X25519" , DOMDataError,
441
441
" A JSON Web Key should have either a Public Key Use parameter (\" use\" ) or a Key "
442
442
" Operations parameter (\" key_ops\" ); otherwise, the parameters must be consistent "
@@ -460,22 +460,22 @@ ImportAsymmetricResult importAsymmetric(jsg::Lock& js, kj::StringPtr format,
460
460
// and the next usages. Test the first usage and the first usage distinct from the first, if
461
461
// present (i.e. the second allowed usage, even if there are duplicates).
462
462
if (keyUsages.size () > 0 ) {
463
- JSG_REQUIRE (std::find (ops-> begin (), ops-> end (), keyUsages.front ()) != ops-> end (),
463
+ JSG_REQUIRE (std::find (ops. begin (), ops. end (), keyUsages.front ()) != ops. end (),
464
464
DOMDataError, " All specified key usages must be present in the JSON "
465
465
" Web Key's Key Operations parameter (\" key_ops\" )." );
466
466
auto secondUsage = std::find_end (keyUsages.begin (), keyUsages.end (), keyUsages.begin (),
467
467
keyUsages.begin () + 1 ) + 1 ;
468
468
if (secondUsage != keyUsages.end ()) {
469
- JSG_REQUIRE (std::find (ops-> begin (), ops-> end (), *secondUsage) != ops-> end (),
469
+ JSG_REQUIRE (std::find (ops. begin (), ops. end (), *secondUsage) != ops. end (),
470
470
DOMDataError, " All specified key usages must be present in the JSON "
471
471
" Web Key's Key Operations parameter (\" key_ops\" )." );
472
472
}
473
473
}
474
474
}
475
475
476
- KJ_IF_MAYBE (ext, keyDataJwk.ext ) {
476
+ KJ_IF_SOME (ext, keyDataJwk.ext ) {
477
477
// If the user requested this key to be extractable, make sure the JWK does not disallow it.
478
- JSG_REQUIRE (!extractable || * ext, DOMDataError,
478
+ JSG_REQUIRE (!extractable || ext, DOMDataError,
479
479
" Cannot create an extractable CryptoKey from an unextractable JSON Web Key." );
480
480
}
481
481
@@ -765,8 +765,8 @@ private:
765
765
" Error doing RSA OAEP encrypt/decrypt (" , " MGF1 digest" , " )" ,
766
766
internalDescribeOpensslErrors ());
767
767
768
- KJ_IF_MAYBE (l, algorithm.label ) {
769
- auto labelCopy = reinterpret_cast <uint8_t *>(OPENSSL_malloc (l-> size ()));
768
+ KJ_IF_SOME (l, algorithm.label ) {
769
+ auto labelCopy = reinterpret_cast <uint8_t *>(OPENSSL_malloc (l. size ()));
770
770
KJ_DEFER (OPENSSL_free (labelCopy));
771
771
// If setting the label fails we need to remember to destroy the buffer. In practice it can't
772
772
// actually happen since we set RSA_PKCS1_OAEP_PADDING above & that appears to be the only way
@@ -775,11 +775,11 @@ private:
775
775
JSG_REQUIRE (labelCopy != nullptr , DOMOperationError,
776
776
" Failed to allocate space for RSA-OAEP label copy" ,
777
777
tryDescribeOpensslErrors ());
778
- std::copy (l-> begin (), l-> end (), labelCopy);
778
+ std::copy (l. begin (), l. end (), labelCopy);
779
779
780
780
// EVP_PKEY_CTX_set0_rsa_oaep_label below takes ownership of the buffer passed in (must have
781
781
// been OPENSSL_malloc-allocated).
782
- JSG_REQUIRE (1 == EVP_PKEY_CTX_set0_rsa_oaep_label (ctx.get (), labelCopy, l-> size ()),
782
+ JSG_REQUIRE (1 == EVP_PKEY_CTX_set0_rsa_oaep_label (ctx.get (), labelCopy, l. size ()),
783
783
DOMOperationError, " Failed to set RSA-OAEP label" ,
784
784
tryDescribeOpensslErrors ());
785
785
@@ -933,7 +933,7 @@ kj::Maybe<T> fromBignum(kj::ArrayPtr<kj::byte> value) {
933
933
size_t bitShift = value.size () - i - 1 ;
934
934
if (bitShift >= sizeof (T) && value[i]) {
935
935
// Too large for desired type.
936
- return nullptr ;
936
+ return kj::none ;
937
937
}
938
938
939
939
asUnsigned |= value[i] << 8 * bitShift;
@@ -963,16 +963,16 @@ void validateRsaParams(jsg::Lock& js, int modulusLength, kj::ArrayPtr<kj::byte>
963
963
// doesn't have convenient APIs to do this (since these are bignums) so we have to do it by hand.
964
964
// Since the problematic BIGNUMs are within the range of an unsigned int (& technicall an
965
965
// unsigned short) we can treat an out-of-range issue as valid input.
966
- KJ_IF_MAYBE (v, fromBignum<unsigned >(publicExponent)) {
966
+ KJ_IF_SOME (v, fromBignum<unsigned >(publicExponent)) {
967
967
if (!isImport) {
968
- JSG_REQUIRE (* v == 3 || * v == 65537 , DOMOperationError,
969
- " The \" publicExponent\" must be either 3 or 65537, but got " , * v, " ." );
968
+ JSG_REQUIRE (v == 3 || v == 65537 , DOMOperationError,
969
+ " The \" publicExponent\" must be either 3 or 65537, but got " , v, " ." );
970
970
} else if (strictCrypto) {
971
971
// While we have long required the exponent to be 3 or 65537 when generating keys, handle
972
972
// imported keys more permissively and allow additional exponents that are considered safe
973
973
// and commonly used.
974
- JSG_REQUIRE (* v == 3 || * v == 17 || * v == 37 || * v == 65537 , DOMOperationError,
975
- " Imported RSA key has invalid publicExponent " , * v, " ." );
974
+ JSG_REQUIRE (v == 3 || v == 17 || v == 37 || v == 65537 , DOMOperationError,
975
+ " Imported RSA key has invalid publicExponent " , v, " ." );
976
976
}
977
977
} else {
978
978
JSG_FAIL_REQUIRE (DOMOperationError, " The \" publicExponent\" must be either 3 or 65537, but "
@@ -1057,7 +1057,7 @@ kj::Own<EVP_PKEY> rsaJwkReader(SubtleCrypto::JsonWebKey&& keyDataJwk) {
1057
1057
BN_bin2bn (publicExponent.begin (), publicExponent.size (), nullptr ),
1058
1058
nullptr ));
1059
1059
1060
- if (keyDataJwk.d != nullptr ) {
1060
+ if (keyDataJwk.d != kj::none ) {
1061
1061
// This is a private key.
1062
1062
1063
1063
auto privateExponent = UNWRAP_JWK_BIGNUM (kj::mv (keyDataJwk.d ),
@@ -1067,9 +1067,9 @@ kj::Own<EVP_PKEY> rsaJwkReader(SubtleCrypto::JsonWebKey&& keyDataJwk) {
1067
1067
OSSLCALL (RSA_set0_key (rsaKey.get (), nullptr , nullptr ,
1068
1068
BN_bin2bn (privateExponent.begin (), privateExponent.size (), nullptr )));
1069
1069
1070
- auto presence = (keyDataJwk.p != nullptr ) + (keyDataJwk.q != nullptr ) +
1071
- (keyDataJwk.dp != nullptr ) + (keyDataJwk.dq != nullptr ) +
1072
- (keyDataJwk.qi != nullptr );
1070
+ auto presence = (keyDataJwk.p != kj::none ) + (keyDataJwk.q != kj::none ) +
1071
+ (keyDataJwk.dp != kj::none ) + (keyDataJwk.dq != kj::none ) +
1072
+ (keyDataJwk.qi != kj::none );
1073
1073
1074
1074
if (presence == 5 ) {
1075
1075
auto firstPrimeFactor = UNWRAP_JWK_BIGNUM (kj::mv (keyDataJwk.p ),
@@ -1131,7 +1131,7 @@ kj::Own<CryptoKey::Impl> CryptoKey::Impl::importRsa(
1131
1131
" RSASSA-PKCS1-v1_5 \" jwk\" key import requires a JSON Web Key with Key Type parameter "
1132
1132
" \" kty\" (\" " , keyDataJwk.kty , " \" ) equal to \" RSA\" ." );
1133
1133
1134
- KJ_IF_MAYBE (alg, keyDataJwk.alg ) {
1134
+ KJ_IF_SOME (alg, keyDataJwk.alg ) {
1135
1135
// If this JWK specifies an algorithm, make sure it jives with the hash we were passed via
1136
1136
// importKey().
1137
1137
static std::map<kj::StringPtr , const EVP_MD*> rsaShaAlgorithms{
@@ -1164,13 +1164,13 @@ kj::Own<CryptoKey::Impl> CryptoKey::Impl::importRsa(
1164
1164
" \" ." );
1165
1165
}
1166
1166
}();
1167
- auto jwkHash = validAlgorithms.find (* alg);
1167
+ auto jwkHash = validAlgorithms.find (alg);
1168
1168
JSG_REQUIRE (jwkHash != rsaPssAlgorithms.end (), DOMNotSupportedError,
1169
- " Unrecognized or unimplemented algorithm \" " , * alg, " \" listed in JSON Web Key Algorithm "
1169
+ " Unrecognized or unimplemented algorithm \" " , alg, " \" listed in JSON Web Key Algorithm "
1170
1170
" parameter." );
1171
1171
1172
1172
JSG_REQUIRE (jwkHash->second == hashEvpMd, DOMDataError,
1173
- " JSON Web Key Algorithm parameter \" alg\" (\" " , * alg, " \" ) does not match requested hash "
1173
+ " JSON Web Key Algorithm parameter \" alg\" (\" " , alg, " \" ) does not match requested hash "
1174
1174
" algorithm \" " , jwkHash->first , " \" ." );
1175
1175
}
1176
1176
@@ -1232,7 +1232,7 @@ kj::Own<CryptoKey::Impl> CryptoKey::Impl::importRsaRaw(
1232
1232
" RSA-RAW \" jwk\" key import requires a JSON Web Key with Key Type parameter "
1233
1233
" \" kty\" (\" " , keyDataJwk.kty , " \" ) equal to \" RSA\" ." );
1234
1234
1235
- KJ_IF_MAYBE (alg, keyDataJwk.alg ) {
1235
+ KJ_IF_SOME (alg, keyDataJwk.alg ) {
1236
1236
// If this JWK specifies an algorithm, make sure it jives with the hash we were passed via
1237
1237
// importKey().
1238
1238
static std::map<kj::StringPtr , const EVP_MD*> rsaAlgorithms{
@@ -1241,9 +1241,9 @@ kj::Own<CryptoKey::Impl> CryptoKey::Impl::importRsaRaw(
1241
1241
{" RS384" , EVP_sha384 ()},
1242
1242
{" RS512" , EVP_sha512 ()},
1243
1243
};
1244
- auto jwkHash = rsaAlgorithms.find (* alg);
1244
+ auto jwkHash = rsaAlgorithms.find (alg);
1245
1245
JSG_REQUIRE (jwkHash != rsaAlgorithms.end (), DOMNotSupportedError,
1246
- " Unrecognized or unimplemented algorithm \" " , * alg,
1246
+ " Unrecognized or unimplemented algorithm \" " , alg,
1247
1247
" \" listed in JSON Web Key Algorithm parameter." );
1248
1248
}
1249
1249
return rsaJwkReader (kj::mv (keyDataJwk));
@@ -1740,12 +1740,12 @@ kj::Own<EVP_PKEY> ellipticJwkReader(int curveId, SubtleCrypto::JsonWebKey&& keyD
1740
1740
" Missing field \" crv\" for " , curveName, " key." );
1741
1741
JSG_REQUIRE (crv == curveName, DOMNotSupportedError,
1742
1742
" Only " , curveName, " is supported but \" " , crv, " \" was requested." );
1743
- KJ_IF_MAYBE (alg, keyDataJwk.alg ) {
1743
+ KJ_IF_SOME (alg, keyDataJwk.alg ) {
1744
1744
// If this JWK specifies an algorithm, make sure it jives with the hash we were passed via
1745
1745
// importKey().
1746
1746
if (curveId == NID_ED25519) {
1747
- JSG_REQUIRE (* alg == " EdDSA" , DOMDataError,
1748
- " JSON Web Key Algorithm parameter \" alg\" (\" " , * alg, " \" ) does not match requested "
1747
+ JSG_REQUIRE (alg == " EdDSA" , DOMDataError,
1748
+ " JSON Web Key Algorithm parameter \" alg\" (\" " , alg, " \" ) does not match requested "
1749
1749
" Ed25519 curve." );
1750
1750
}
1751
1751
}
@@ -1754,7 +1754,7 @@ kj::Own<EVP_PKEY> ellipticJwkReader(int curveId, SubtleCrypto::JsonWebKey&& keyD
1754
1754
" Invalid " , crv, " key in JSON WebKey; missing or invalid public key component (\" x\" )." );
1755
1755
JSG_REQUIRE (x.size () == 32 , DOMDataError, " Invalid length " , x.size (), " for public key" );
1756
1756
1757
- if (keyDataJwk.d == nullptr ) {
1757
+ if (keyDataJwk.d == kj::none ) {
1758
1758
// This is a public key.
1759
1759
return OSSLCALL_OWN (EVP_PKEY, EVP_PKEY_new_raw_public_key (evpId, nullptr ,
1760
1760
x.begin (), x.size ()), InternalDOMOperationError,
@@ -1781,7 +1781,7 @@ kj::Own<EVP_PKEY> ellipticJwkReader(int curveId, SubtleCrypto::JsonWebKey&& keyD
1781
1781
" Elliptic curve \" jwk\" key import requires a JSON Web Key with Key Type parameter "
1782
1782
" \" kty\" (\" " , keyDataJwk.kty , " \" ) equal to \" EC\" ." );
1783
1783
1784
- KJ_IF_MAYBE (alg, keyDataJwk.alg ) {
1784
+ KJ_IF_SOME (alg, keyDataJwk.alg ) {
1785
1785
// If this JWK specifies an algorithm, make sure it jives with the hash we were passed via
1786
1786
// importKey().
1787
1787
static std::map<kj::StringPtr , int > ecdsaAlgorithms {
@@ -1790,13 +1790,13 @@ kj::Own<EVP_PKEY> ellipticJwkReader(int curveId, SubtleCrypto::JsonWebKey&& keyD
1790
1790
{" ES512" , NID_secp521r1},
1791
1791
};
1792
1792
1793
- auto iter = ecdsaAlgorithms.find (* alg);
1793
+ auto iter = ecdsaAlgorithms.find (alg);
1794
1794
JSG_REQUIRE (iter != ecdsaAlgorithms.end (), DOMNotSupportedError,
1795
- " Unrecognized or unimplemented algorithm \" " , * alg,
1795
+ " Unrecognized or unimplemented algorithm \" " , alg,
1796
1796
" \" listed in JSON Web Key Algorithm parameter." );
1797
1797
1798
1798
JSG_REQUIRE (iter->second == curveId, DOMDataError,
1799
- " JSON Web Key Algorithm parameter \" alg\" (\" " , * alg, " \" ) does not match requested curve." );
1799
+ " JSON Web Key Algorithm parameter \" alg\" (\" " , alg, " \" ) does not match requested curve." );
1800
1800
}
1801
1801
1802
1802
auto ecKey = OSSLCALL_OWN (EC_KEY, EC_KEY_new_by_curve_name (curveId), DOMOperationError,
@@ -1816,7 +1816,7 @@ kj::Own<EVP_PKEY> ellipticJwkReader(int curveId, SubtleCrypto::JsonWebKey&& keyD
1816
1816
OSSLCALL (EC_POINT_set_affine_coordinates_GFp (group, point, bigX, bigY, nullptr ));
1817
1817
OSSLCALL (EC_KEY_set_public_key (ecKey, point));
1818
1818
1819
- if (keyDataJwk.d != nullptr ) {
1819
+ if (keyDataJwk.d != kj::none ) {
1820
1820
// This is a private key.
1821
1821
1822
1822
auto d = UNWRAP_JWK_BIGNUM (kj::mv (keyDataJwk.d ), DOMDataError,
0 commit comments