GeezerVison is showing github.com — src: use Maybe<void> in ManagedEVPPKey · nodejs/node@1a4da22
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: src/crypto/crypto_ec.cc +9-10Lines changed: 9 additions & 10 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -840,10 +840,9 @@ Maybe<void> ExportJWKEcKey( | 840 | 840 | return JustVoid(); | 841 | 841 | } | 842 | 842 |
| 843 | | -Maybe<bool> ExportJWKEdKey( | 844 | | - Environment* env, | 845 | | - std::shared_ptr<KeyObjectData> key, | 846 | | - Local<Object> target) { | | 843 | +Maybe<void> ExportJWKEdKey(Environment* env, | | 844 | + std::shared_ptr<KeyObjectData> key, | | 845 | + Local<Object> target) { | 847 | 846 | ManagedEVPPKey pkey = key->GetAsymmetricKey(); | 848 | 847 | Mutex::ScopedLock lock(*pkey.mutex()); | 849 | 848 |
| @@ -868,15 +867,15 @@ Maybe<bool> ExportJWKEdKey( | 868 | 867 | env->context(), | 869 | 868 | env->jwk_crv_string(), | 870 | 869 | OneByteString(env->isolate(), curve)).IsNothing()) { | 871 | | - return Nothing<bool>(); | | 870 | + return Nothing<void>(); | 872 | 871 | } | 873 | 872 |
| 874 | 873 | size_t len = 0; | 875 | 874 | Local<Value> encoded; | 876 | 875 | Local<Value> error; | 877 | 876 |
| 878 | 877 | if (!EVP_PKEY_get_raw_public_key(pkey.get(), nullptr, &len)) | 879 | | - return Nothing<bool>(); | | 878 | + return Nothing<void>(); | 880 | 879 |
| 881 | 880 | ByteSource::Builder out(len); | 882 | 881 |
| @@ -889,7 +888,7 @@ Maybe<bool> ExportJWKEdKey( | 889 | 888 | !target->Set(env->context(), env->jwk_d_string(), encoded).IsJust()) { | 890 | 889 | if (!error.IsEmpty()) | 891 | 890 | env->isolate()->ThrowException(error); | 892 | | - return Nothing<bool>(); | | 891 | + return Nothing<void>(); | 893 | 892 | } | 894 | 893 | } | 895 | 894 |
| @@ -901,17 +900,17 @@ Maybe<bool> ExportJWKEdKey( | 901 | 900 | !target->Set(env->context(), env->jwk_x_string(), encoded).IsJust()) { | 902 | 901 | if (!error.IsEmpty()) | 903 | 902 | env->isolate()->ThrowException(error); | 904 | | - return Nothing<bool>(); | | 903 | + return Nothing<void>(); | 905 | 904 | } | 906 | 905 |
| 907 | 906 | if (target->Set( | 908 | 907 | env->context(), | 909 | 908 | env->jwk_kty_string(), | 910 | 909 | env->jwk_okp_string()).IsNothing()) { | 911 | | - return Nothing<bool>(); | | 910 | + return Nothing<void>(); | 912 | 911 | } | 913 | 912 |
| 914 | | - return Just(true); | | 913 | + return JustVoid(); | 915 | 914 | } | 916 | 915 |
| 917 | 916 | std::shared_ptr<KeyObjectData> ImportJWKEcKey( | |
Collapse file Copy file name to clipboardExpand all lines: src/crypto/crypto_ec.h +3-4Lines changed: 3 additions & 4 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -148,10 +148,9 @@ v8::Maybe<void> ExportJWKEcKey( | 148 | 148 | std::shared_ptr<KeyObjectData> key, | 149 | 149 | v8::Local<v8::Object> target); | 150 | 150 |
| 151 | | -v8::Maybe<bool> ExportJWKEdKey( | 152 | | - Environment* env, | 153 | | - std::shared_ptr<KeyObjectData> key, | 154 | | - v8::Local<v8::Object> target); | | 151 | +v8::Maybe<void> ExportJWKEdKey(Environment* env, | | 152 | + std::shared_ptr<KeyObjectData> key, | | 153 | + v8::Local<v8::Object> target); | 155 | 154 |
| 156 | 155 | std::shared_ptr<KeyObjectData> ImportJWKEcKey( | 157 | 156 | Environment* env, | |
Collapse file Copy file name to clipboardExpand all lines: src/crypto/crypto_keys.cc +27-29Lines changed: 27 additions & 29 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -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> | |
Collapse file Copy file name to clipboardExpand all lines: src/crypto/crypto_keys.h +2-2Lines changed: 2 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -112,11 +112,11 @@ class ManagedEVPPKey : public MemoryRetainer { | 112 | 112 | unsigned int* offset, | 113 | 113 | bool allow_key_object); | 114 | 114 |
| 115 | | - v8::Maybe<bool> ToEncodedPublicKey(Environment* env, | | 115 | + v8::Maybe<void> ToEncodedPublicKey(Environment* env, | 116 | 116 | const PublicKeyEncodingConfig& config, | 117 | 117 | v8::Local<v8::Value>* out); | 118 | 118 |
| 119 | | - v8::Maybe<bool> ToEncodedPrivateKey(Environment* env, | | 119 | + v8::Maybe<void> ToEncodedPrivateKey(Environment* env, | 120 | 120 | const PrivateKeyEncodingConfig& config, | 121 | 121 | v8::Local<v8::Value>* out); | 122 | 122 |
| |
Collapse file Copy file name to clipboardExpand all lines: src/crypto/crypto_rsa.cc +8-8Lines changed: 8 additions & 8 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -19,6 +19,7 @@ using v8::BackingStore; | 19 | 19 | using v8::FunctionCallbackInfo; | 20 | 20 | using v8::Int32; | 21 | 21 | using v8::Just; | | 22 | +using v8::JustVoid; | 22 | 23 | using v8::Local; | 23 | 24 | using v8::Maybe; | 24 | 25 | using v8::Nothing; | @@ -359,10 +360,9 @@ WebCryptoCipherStatus RSACipherTraits::DoCipher( | 359 | 360 | return WebCryptoCipherStatus::FAILED; | 360 | 361 | } | 361 | 362 |
| 362 | | -Maybe<bool> ExportJWKRsaKey( | 363 | | - Environment* env, | 364 | | - std::shared_ptr<KeyObjectData> key, | 365 | | - Local<Object> target) { | | 363 | +Maybe<void> ExportJWKRsaKey(Environment* env, | | 364 | + std::shared_ptr<KeyObjectData> key, | | 365 | + Local<Object> target) { | 366 | 366 | ManagedEVPPKey m_pkey = key->GetAsymmetricKey(); | 367 | 367 | Mutex::ScopedLock lock(*m_pkey.mutex()); | 368 | 368 | int type = EVP_PKEY_id(m_pkey.get()); | @@ -392,12 +392,12 @@ Maybe<bool> ExportJWKRsaKey( | 392 | 392 | env->context(), | 393 | 393 | env->jwk_kty_string(), | 394 | 394 | env->jwk_rsa_string()).IsNothing()) { | 395 | | - return Nothing<bool>(); | | 395 | + return Nothing<void>(); | 396 | 396 | } | 397 | 397 |
| 398 | 398 | if (SetEncodedValue(env, target, env->jwk_n_string(), n).IsNothing() || | 399 | 399 | SetEncodedValue(env, target, env->jwk_e_string(), e).IsNothing()) { | 400 | | - return Nothing<bool>(); | | 400 | + return Nothing<void>(); | 401 | 401 | } | 402 | 402 |
| 403 | 403 | if (key->GetKeyType() == kKeyTypePrivate) { | @@ -409,11 +409,11 @@ Maybe<bool> ExportJWKRsaKey( | 409 | 409 | SetEncodedValue(env, target, env->jwk_dp_string(), dp).IsNothing() || | 410 | 410 | SetEncodedValue(env, target, env->jwk_dq_string(), dq).IsNothing() || | 411 | 411 | SetEncodedValue(env, target, env->jwk_qi_string(), qi).IsNothing()) { | 412 | | - return Nothing<bool>(); | | 412 | + return Nothing<void>(); | 413 | 413 | } | 414 | 414 | } | 415 | 415 |
| 416 | | - return Just(true); | | 416 | + return JustVoid(); | 417 | 417 | } | 418 | 418 |
| 419 | 419 | std::shared_ptr<KeyObjectData> ImportJWKRsaKey( | |
Collapse file Copy file name to clipboardExpand all lines: src/crypto/crypto_rsa.h +3-4Lines changed: 3 additions & 4 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -114,10 +114,9 @@ struct RSACipherTraits final { | 114 | 114 |
| 115 | 115 | using RSACipherJob = CipherJob<RSACipherTraits>; | 116 | 116 |
| 117 | | -v8::Maybe<bool> ExportJWKRsaKey( | 118 | | - Environment* env, | 119 | | - std::shared_ptr<KeyObjectData> key, | 120 | | - v8::Local<v8::Object> target); | | 117 | +v8::Maybe<void> ExportJWKRsaKey(Environment* env, | | 118 | + std::shared_ptr<KeyObjectData> key, | | 119 | + v8::Local<v8::Object> target); | 121 | 120 |
| 122 | 121 | std::shared_ptr<KeyObjectData> ImportJWKRsaKey( | 123 | 122 | Environment* env, | |
|