@@ -26,6 +26,7 @@ using v8::FunctionTemplate;
26
26
using v8::Int32;
27
27
using v8::Isolate;
28
28
using v8::Just;
29
+ using v8::JustVoid;
29
30
using v8::Local;
30
31
using v8::Maybe;
31
32
using v8::MaybeLocal;
@@ -431,10 +432,9 @@ MaybeLocal<Value> WritePublicKey(Environment* env,
431
432
return BIOToStringOrBuffer (env, bio.get (), config.format_ );
432
433
}
433
434
434
- Maybe<bool > ExportJWKSecretKey (
435
- Environment* env,
436
- std::shared_ptr<KeyObjectData> key,
437
- Local<Object> target) {
435
+ Maybe<void > ExportJWKSecretKey (Environment* env,
436
+ std::shared_ptr<KeyObjectData> key,
437
+ Local<Object> target) {
438
438
CHECK_EQ (key->GetKeyType (), kKeyTypeSecret );
439
439
440
440
Local<Value> error;
@@ -449,10 +449,9 @@ Maybe<bool> ExportJWKSecretKey(
449
449
if (key_data.IsEmpty ()) {
450
450
CHECK (!error.IsEmpty ());
451
451
env->isolate ()->ThrowException (error);
452
- return Nothing<bool >();
452
+ return Nothing<void >();
453
453
}
454
- if (!key_data.ToLocal (&raw))
455
- return Nothing<bool >();
454
+ if (!key_data.ToLocal (&raw)) return Nothing<void >();
456
455
457
456
if (target->Set (
458
457
env->context (),
@@ -462,10 +461,10 @@ Maybe<bool> ExportJWKSecretKey(
462
461
env->context (),
463
462
env->jwk_k_string (),
464
463
raw).IsNothing ()) {
465
- return Nothing<bool >();
464
+ return Nothing<void >();
466
465
}
467
466
468
- return Just ( true );
467
+ return JustVoid ( );
469
468
}
470
469
471
470
std::shared_ptr<KeyObjectData> ImportJWKSecretKey (
@@ -483,19 +482,18 @@ std::shared_ptr<KeyObjectData> ImportJWKSecretKey(
483
482
return KeyObjectData::CreateSecret (std::move (key_data));
484
483
}
485
484
486
- Maybe<bool > ExportJWKAsymmetricKey (
487
- Environment* env,
488
- std::shared_ptr<KeyObjectData> key,
489
- Local<Object> target,
490
- bool handleRsaPss) {
485
+ Maybe<void > ExportJWKAsymmetricKey (Environment* env,
486
+ std::shared_ptr<KeyObjectData> key,
487
+ Local<Object> target,
488
+ bool handleRsaPss) {
491
489
switch (EVP_PKEY_id (key->GetAsymmetricKey ().get ())) {
492
490
case EVP_PKEY_RSA_PSS: {
493
491
if (handleRsaPss) return ExportJWKRsaKey (env, key, target);
494
492
break ;
495
493
}
496
494
case EVP_PKEY_RSA: return ExportJWKRsaKey (env, key, target);
497
- case EVP_PKEY_EC: return ExportJWKEcKey (env, key, target). IsJust () ?
498
- Just ( true ) : Nothing< bool >( );
495
+ case EVP_PKEY_EC:
496
+ return ExportJWKEcKey (env, key, target );
499
497
case EVP_PKEY_ED25519:
500
498
// Fall through
501
499
case EVP_PKEY_ED448:
@@ -505,7 +503,7 @@ Maybe<bool> ExportJWKAsymmetricKey(
505
503
case EVP_PKEY_X448: return ExportJWKEdKey (env, key, target);
506
504
}
507
505
THROW_ERR_CRYPTO_JWK_UNSUPPORTED_KEY_TYPE (env);
508
- return Nothing<bool >();
506
+ return Nothing<void >();
509
507
}
510
508
511
509
std::shared_ptr<KeyObjectData> ImportJWKAsymmetricKey (
@@ -605,12 +603,12 @@ size_t ManagedEVPPKey::size_of_public_key() const {
605
603
pkey_.get (), nullptr , &len) == 1 ) ? len : 0 ;
606
604
}
607
605
608
- // This maps true to Just<bool>(true) and false to Nothing<bool >().
609
- static inline Maybe<bool > Tristate (bool b) {
610
- return b ? Just ( true ) : Nothing<bool >();
606
+ // This maps true to JustVoid and false to Nothing<void >().
607
+ static inline Maybe<void > NothingIfFalse (bool b) {
608
+ return b ? JustVoid ( ) : Nothing<void >();
611
609
}
612
610
613
- Maybe<bool > ExportJWKInner (Environment* env,
611
+ Maybe<void > ExportJWKInner (Environment* env,
614
612
std::shared_ptr<KeyObjectData> key,
615
613
Local<Value> result,
616
614
bool handleRsaPss) {
@@ -627,44 +625,44 @@ Maybe<bool> ExportJWKInner(Environment* env,
627
625
}
628
626
}
629
627
630
- Maybe<bool > ManagedEVPPKey::ToEncodedPublicKey (
628
+ Maybe<void > ManagedEVPPKey::ToEncodedPublicKey (
631
629
Environment* env,
632
630
const PublicKeyEncodingConfig& config,
633
631
Local<Value>* out) {
634
- if (!*this ) return Nothing<bool >();
632
+ if (!*this ) return Nothing<void >();
635
633
if (config.output_key_object_ ) {
636
634
// Note that this has the downside of containing sensitive data of the
637
635
// private key.
638
636
std::shared_ptr<KeyObjectData> data =
639
637
KeyObjectData::CreateAsymmetric (kKeyTypePublic , *this );
640
- return Tristate (KeyObjectHandle::Create (env, data).ToLocal (out));
638
+ return NothingIfFalse (KeyObjectHandle::Create (env, data).ToLocal (out));
641
639
} else if (config.format_ == kKeyFormatJWK ) {
642
640
std::shared_ptr<KeyObjectData> data =
643
641
KeyObjectData::CreateAsymmetric (kKeyTypePublic , *this );
644
642
*out = Object::New (env->isolate ());
645
643
return ExportJWKInner (env, data, *out, false );
646
644
}
647
645
648
- return Tristate (WritePublicKey (env, get (), config).ToLocal (out));
646
+ return NothingIfFalse (WritePublicKey (env, get (), config).ToLocal (out));
649
647
}
650
648
651
- Maybe<bool > ManagedEVPPKey::ToEncodedPrivateKey (
649
+ Maybe<void > ManagedEVPPKey::ToEncodedPrivateKey (
652
650
Environment* env,
653
651
const PrivateKeyEncodingConfig& config,
654
652
Local<Value>* out) {
655
- if (!*this ) return Nothing<bool >();
653
+ if (!*this ) return Nothing<void >();
656
654
if (config.output_key_object_ ) {
657
655
std::shared_ptr<KeyObjectData> data =
658
656
KeyObjectData::CreateAsymmetric (kKeyTypePrivate , *this );
659
- return Tristate (KeyObjectHandle::Create (env, data).ToLocal (out));
657
+ return NothingIfFalse (KeyObjectHandle::Create (env, data).ToLocal (out));
660
658
} else if (config.format_ == kKeyFormatJWK ) {
661
659
std::shared_ptr<KeyObjectData> data =
662
660
KeyObjectData::CreateAsymmetric (kKeyTypePrivate , *this );
663
661
*out = Object::New (env->isolate ());
664
662
return ExportJWKInner (env, data, *out, false );
665
663
}
666
664
667
- return Tristate (WritePrivateKey (env, get (), config).ToLocal (out));
665
+ return NothingIfFalse (WritePrivateKey (env, get (), config).ToLocal (out));
668
666
}
669
667
670
668
NonCopyableMaybe<PrivateKeyEncodingConfig>
0 commit comments