@@ -348,8 +348,7 @@ std::optional<StringOrBuffer> WritePrivateKey(
348
348
}
349
349
350
350
if (err) {
351
- jsi::detail::throwJSError (runtime, " Failed to encode private key" );
352
- return {};
351
+ throw jsi::JSError (runtime, " Failed to encode private key" );
353
352
}
354
353
355
354
return BIOToStringOrBuffer (bio.get (), config.format_ );
@@ -389,8 +388,7 @@ std::optional<StringOrBuffer> WritePublicKey(
389
388
// CHECK(bio);
390
389
391
390
if (!WritePublicKeyInner (pkey, bio, config)) {
392
- jsi::detail::throwJSError (runtime, " Failed to encode public key" );
393
- return std::nullopt ;
391
+ throw jsi::JSError (runtime, " Failed to encode public key" );
394
392
}
395
393
396
394
return BIOToStringOrBuffer (bio.get (), config.format_ );
@@ -648,8 +646,7 @@ ManagedEVPPKey::GetPrivateKeyEncodingFromJs(jsi::Runtime& runtime,
648
646
auto cipher_name = arguments[*offset].getString (runtime).utf8 (runtime);
649
647
result.cipher_ = EVP_get_cipherbyname (cipher_name.c_str ());
650
648
if (result.cipher_ == nullptr ) {
651
- jsi::detail::throwJSError (runtime, " Unknown cipher" );
652
- return NonCopyableMaybe<PrivateKeyEncodingConfig>();
649
+ throw jsi::JSError (runtime, " Unknown cipher" );
653
650
}
654
651
needs_passphrase = true ;
655
652
} else {
@@ -666,15 +663,15 @@ ManagedEVPPKey::GetPrivateKeyEncodingFromJs(jsi::Runtime& runtime,
666
663
jsi::ArrayBuffer passphrase =
667
664
arguments[*offset].asObject (runtime).getArrayBuffer (runtime);
668
665
if (!CheckSizeInt32 (runtime, passphrase)) {
669
- jsi::detail::throwJSError (runtime, " passphrase is too long" );
666
+ throw jsi::JSError (runtime, " passphrase is too long" );
670
667
}
671
668
672
669
result.passphrase_ = NonCopyableMaybe<ByteSource>(
673
670
ToNullTerminatedByteSource (runtime, passphrase));
674
671
} else {
675
672
if (needs_passphrase &&
676
673
(arguments[*offset].isNull () || arguments[*offset].isUndefined ())) {
677
- jsi::detail::throwJSError (
674
+ throw jsi::JSError (
678
675
runtime, " passphrase is null or unfedined but it is required" );
679
676
}
680
677
}
@@ -728,7 +725,7 @@ ManagedEVPPKey ManagedEVPPKey::GetPublicOrPrivateKeyFromJs(
728
725
args[(*offset)++].asObject (runtime).getArrayBuffer (runtime);
729
726
730
727
if (!CheckSizeInt32 (runtime, dataArrayBuffer)) {
731
- jsi::detail::throwJSError (runtime, " data is too big" );
728
+ throw jsi::JSError (runtime, " data is too big" );
732
729
}
733
730
734
731
NonCopyableMaybe<PrivateKeyEncodingConfig> config_ =
@@ -766,7 +763,6 @@ ManagedEVPPKey ManagedEVPPKey::GetPublicOrPrivateKeyFromJs(
766
763
is_public = false ;
767
764
break ;
768
765
default :
769
- jsi::detail::throwJSError (runtime, " Invalid key encoding type" );
770
766
throw new jsi::JSError (runtime, " Invalid key encoding type" );
771
767
}
772
768
@@ -784,9 +780,6 @@ ManagedEVPPKey ManagedEVPPKey::GetPublicOrPrivateKeyFromJs(
784
780
return ManagedEVPPKey::GetParsedKey (runtime, std::move (pkey), ret,
785
781
" Failed to read asymmetric key" );
786
782
} else {
787
- jsi::detail::throwJSError (runtime,
788
- " publicEncrypt api only supports ArrayBuffer keys"
789
- " for now" );
790
783
throw new jsi::JSError (
791
784
runtime, " public encrypt only supports ArrayBuffer at the moment" );
792
785
// CHECK(args[*offset]->IsObject());
@@ -808,11 +801,10 @@ ManagedEVPPKey ManagedEVPPKey::GetParsedKey(jsi::Runtime& runtime,
808
801
// CHECK(pkey);
809
802
break ;
810
803
case ParseKeyResult::kParseKeyNeedPassphrase :
811
- jsi::detail::throwJSError (runtime,
804
+ throw jsi::JSError (runtime,
812
805
" Passphrase required for encrypted key" );
813
806
break ;
814
807
default :
815
- jsi::detail::throwJSError (runtime, default_msg);
816
808
throw new jsi::JSError (runtime, default_msg);
817
809
}
818
810
0 commit comments