From ac7da205c909778c5521ae72d54d285d67dc628b Mon Sep 17 00:00:00 2001 From: lyujiayi <654765554@qq.com> Date: Sat, 19 Jul 2025 16:33:06 +0800 Subject: [PATCH] fix: modify the overload method Signed-off-by: lyujiayi <654765554@qq.com> --- ...rity.cryptoFramework.cryptoFramework.taihe | 118 ++++++++----- frameworks/js/ani/inc/ani_asy_key_generator.h | 4 + .../ani/inc/ani_asy_key_generator_by_spec.h | 2 + frameworks/js/ani/inc/ani_cipher.h | 6 + frameworks/js/ani/inc/ani_mac.h | 6 + frameworks/js/ani/inc/ani_md.h | 4 + frameworks/js/ani/inc/ani_sign.h | 4 + frameworks/js/ani/inc/ani_sym_key_generator.h | 4 + frameworks/js/ani/inc/ani_verify.h | 6 + .../js/ani/src/ani_asy_key_generator.cpp | 21 +++ .../ani/src/ani_asy_key_generator_by_spec.cpp | 10 ++ frameworks/js/ani/src/ani_cipher.cpp | 30 ++++ frameworks/js/ani/src/ani_mac.cpp | 38 ++++- frameworks/js/ani/src/ani_md.cpp | 20 +++ frameworks/js/ani/src/ani_sign.cpp | 20 +++ .../js/ani/src/ani_sym_key_generator.cpp | 20 +++ frameworks/js/ani/src/ani_verify.cpp | 30 ++++ ...y.cryptoFramework.cryptoFramework.impl.cpp | 160 +++++++++++++++++- 18 files changed, 455 insertions(+), 48 deletions(-) diff --git a/frameworks/js/ani/idl/ohos.security.cryptoFramework.cryptoFramework.taihe b/frameworks/js/ani/idl/ohos.security.cryptoFramework.cryptoFramework.taihe index 8ae1bbe..ad7d07c 100644 --- a/frameworks/js/ani/idl/ohos.security.cryptoFramework.cryptoFramework.taihe +++ b/frameworks/js/ani/idl/ohos.security.cryptoFramework.cryptoFramework.taihe @@ -58,11 +58,15 @@ union OptIntUint8Arr { } interface Md { - @gen_async("update") - @gen_promise("update") + @static_overload("update") + @async UpdateWithCallback(input: DataBlob): void; + @static_overload("update") + @promise UpdateReturnsPromise(input: DataBlob): void; UpdateSync(input: DataBlob): void; - @gen_async("digest") - @gen_promise("digest") + @static_overload("digest") + @async DigestWithCallback(): DataBlob; + @static_overload("digest") + @promise DigestReturnsPromise(): DataBlob; DigestSync(): DataBlob; GetMdLength(): i32; @get("algName") GetAlgName(): String; @@ -99,22 +103,28 @@ union OptExtMacSpec { } interface Mac { - @gen_async("init") - @gen_promise("init") + @static_overload("init") + @async InitWithCallback(key: SymKey): void; + @static_overload("init") + @promise InitReturnsPromise(key: SymKey): void; InitSync(key: SymKey): void; - @gen_async("update") - @gen_promise("update") + @static_overload("update") + @async UpdateWithCallback(input: DataBlob): void; + @static_overload("update") + @promise UpdateReturnsPromise(input: DataBlob): void; UpdateSync(input: DataBlob): void; - @gen_async("doFinal") - @gen_promise("doFinal") + @static_overload("doFinal") + @async DoFinalWithCallback(): DataBlob; + @static_overload("doFinal") + @promise DoFinalReturnsPromise(): DataBlob; DoFinalSync(): DataBlob; GetMacLength(): i32; @get("algName") GetAlgName(): String; } -@overload("createMac") -function CreateMacByStr(algName: String): Mac; -@overload("createMac") -function CreateMacBySpec(macSpec: OptExtMacSpec): Mac; +@static_overload("createMac") +function CreateMacWithAlgName(algName: String): Mac; +@static_overload("createMac") +function CreateMacWithMacSpec(macSpec: OptExtMacSpec): Mac; interface Key { GetKeyObj(): i64; @@ -223,23 +233,33 @@ interface SymKey: Key { } interface SymKeyGenerator { - @gen_async("generateSymKey") - @gen_promise("generateSymKey") + @static_overload("generateSymKey") + @async GenerateSymKeyWithCallback(): SymKey; + @static_overload("generateSymKey") + @promise GenerateSymKeyReturnsPromise(): SymKey; GenerateSymKeySync(): SymKey; - @gen_async("convertKey") - @gen_promise("convertKey") + @static_overload("convertKey") + @async ConvertKeyWithKeyCallback(key: DataBlob): SymKey; + @static_overload("convertKey") + @promise ConvertKeyWithKeyReturnsPromise(key: DataBlob): SymKey; ConvertKeySync(key: DataBlob): SymKey; @get("algName") GetAlgName(): String; } function CreateSymKeyGenerator(algName: String): SymKeyGenerator; interface AsyKeyGenerator { - @gen_async("generateKeyPair") - @gen_promise("generateKeyPair") + @static_overload("generateKeyPair") + @async GenerateKeyPairWithCallback(): KeyPair; + @static_overload("generateKeyPair") + @promise GenerateKeyPairReturnsPromise(): KeyPair; GenerateKeyPairSync(): KeyPair; - @gen_async("convertKey") - @gen_promise("convertKey") + + @static_overload("convertKey") + @async ConvertKeyWithPubKeyPriKeyCallback(pubKey: OptDataBlob, priKey: OptDataBlob): KeyPair; + @static_overload("convertKey") + @promise ConvertKeyWithPubKeyPriKeyReturnsPromise(pubKey: OptDataBlob, priKey: OptDataBlob): KeyPair; ConvertKeySync(pubKey: OptDataBlob, priKey: OptDataBlob): KeyPair; + @gen_async("convertPemKey") @gen_promise("convertPemKey") @overload("convertPemKeySync") @@ -339,14 +359,20 @@ union OptParamsSpec { } interface Cipher { - @gen_async("init") - @gen_promise("init") + @static_overload("init") + @async InitWithCallback(opMode: CryptoMode, key: Key, params: OptParamsSpec): void; + @static_overload("init") + @promise InitReturnsPromise(opMode: CryptoMode, key: Key, params: OptParamsSpec): void; InitSync(opMode: CryptoMode, key: Key, params: OptParamsSpec): void; - @gen_async("update") - @gen_promise("update") + @static_overload("update") + @async UpdateWithCallback(input: DataBlob): DataBlob; + @static_overload("update") + @promise UpdateReturnsPromise(input: DataBlob): DataBlob; UpdateSync(input: DataBlob): DataBlob; - @gen_async("doFinal") - @gen_promise("doFinal") + @static_overload("doFinal") + @async DoFinalWithDataCallback(input: OptDataBlob): DataBlob; + @static_overload("doFinal") + @promise DoFinalWithDataReturnsPromise(input: OptDataBlob): DataBlob; DoFinalSync(input: OptDataBlob): DataBlob; SetCipherSpec(itemType: CipherSpecItem, itemValue: @typedarray Array): void; GetCipherSpec(itemType: CipherSpecItem): OptStrUint8Arr; @@ -355,14 +381,20 @@ interface Cipher { function CreateCipher(transformation: String): Cipher; interface Verify { - @gen_async("init") - @gen_promise("init") + @static_overload("init") + @async InitWithCallback(pubKey: PubKey): void; + @static_overload("init") + @promise InitReturnsPromise(pubKey: PubKey): void; InitSync(pubKey: PubKey): void; - @gen_async("update") - @gen_promise("update") + @static_overload("update") + @async UpdateWithCallback(input: DataBlob): void; + @static_overload("update") + @promise UpdateReturnsPromise(input: DataBlob): void; UpdateSync(input: DataBlob): void; - @gen_async("verify") - @gen_promise("verify") + @static_overload("verify") + @async VerifyWithCallback(data: OptDataBlob, signature: DataBlob): bool; + @static_overload("verify") + @promise VerifyReturnsPromise(data: OptDataBlob, signature: DataBlob): bool; VerifySync(data: OptDataBlob, signature: DataBlob): bool; @gen_async("recover") @gen_promise("recover") @@ -374,11 +406,15 @@ interface Verify { function CreateVerify(algName: String): Verify; interface Sign { - @gen_async("init") - @gen_promise("init") + @static_overload("init") + @async InitWithCallback(priKey: PriKey): void; + @static_overload("init") + @promise InitReturnsPromise(priKey: PriKey): void; InitSync(priKey: PriKey): void; - @gen_async("update") - @gen_promise("update") + @static_overload("update") + @async UpdateWithCallback(data: DataBlob): void; + @static_overload("update") + @promise UpdateReturnsPromise(data: DataBlob): void; UpdateSync(data: DataBlob): void; @gen_async("sign") @gen_promise("sign") @@ -575,8 +611,10 @@ union OptAsyKeySpec { } interface AsyKeyGeneratorBySpec { - @gen_async("generateKeyPair") - @gen_promise("generateKeyPair") + @static_overload("generateKeyPair") + @async GenerateKeyPairWithCallback(): KeyPair; + @static_overload("generateKeyPair") + @promise GenerateKeyPairReturnsPromise(): KeyPair; GenerateKeyPairSync(): KeyPair; @gen_async("generatePriKey") @gen_promise("generatePriKey") diff --git a/frameworks/js/ani/inc/ani_asy_key_generator.h b/frameworks/js/ani/inc/ani_asy_key_generator.h index 8b5eba6..8331709 100644 --- a/frameworks/js/ani/inc/ani_asy_key_generator.h +++ b/frameworks/js/ani/inc/ani_asy_key_generator.h @@ -27,7 +27,11 @@ public: ~AsyKeyGeneratorImpl(); KeyPair GenerateKeyPairSync(); + KeyPair GenerateKeyPairWithCallback(); + KeyPair GenerateKeyPairReturnsPromise(); KeyPair ConvertKeySync(OptDataBlob const& pubKey, OptDataBlob const& priKey); + KeyPair ConvertKeyWithPubKeyPriKeyCallback(OptDataBlob const& pubKey, OptDataBlob const& priKey); + KeyPair ConvertKeyWithPubKeyPriKeyReturnsPromise(OptDataBlob const& pubKey, OptDataBlob const& priKey); KeyPair ConvertPemKeySync(OptString const& pubKey, OptString const& priKey); KeyPair ConvertPemKeySyncEx(OptString const& pubKey, OptString const& priKey, string_view password); string GetAlgName(); diff --git a/frameworks/js/ani/inc/ani_asy_key_generator_by_spec.h b/frameworks/js/ani/inc/ani_asy_key_generator_by_spec.h index 27754f8..a974ece 100644 --- a/frameworks/js/ani/inc/ani_asy_key_generator_by_spec.h +++ b/frameworks/js/ani/inc/ani_asy_key_generator_by_spec.h @@ -27,6 +27,8 @@ public: ~AsyKeyGeneratorBySpecImpl(); KeyPair GenerateKeyPairSync(); + KeyPair GenerateKeyPairWithCallback(); + KeyPair GenerateKeyPairReturnsPromise(); PriKey GeneratePriKeySync(); PubKey GeneratePubKeySync(); string GetAlgName(); diff --git a/frameworks/js/ani/inc/ani_cipher.h b/frameworks/js/ani/inc/ani_cipher.h index 2a57537..4bbac4d 100644 --- a/frameworks/js/ani/inc/ani_cipher.h +++ b/frameworks/js/ani/inc/ani_cipher.h @@ -27,8 +27,14 @@ public: ~CipherImpl(); void InitSync(CryptoMode opMode, weak::Key key, OptParamsSpec const& params); + void InitWithCallback(CryptoMode opMode, weak::Key key, OptParamsSpec const& params); + void InitReturnsPromise(CryptoMode opMode, weak::Key key, OptParamsSpec const& params); DataBlob UpdateSync(DataBlob const& input); + DataBlob UpdateWithCallback(DataBlob const& input); + DataBlob UpdateReturnsPromise(DataBlob const& input); DataBlob DoFinalSync(OptDataBlob const& input); + DataBlob DoFinalWithDataCallback(OptDataBlob const& input); + DataBlob DoFinalWithDataReturnsPromise(OptDataBlob const& input); void SetCipherSpec(ThCipherSpecItem itemType, array_view itemValue); OptStrUint8Arr GetCipherSpec(ThCipherSpecItem itemType); string GetAlgName(); diff --git a/frameworks/js/ani/inc/ani_mac.h b/frameworks/js/ani/inc/ani_mac.h index b795047..9bffdbf 100644 --- a/frameworks/js/ani/inc/ani_mac.h +++ b/frameworks/js/ani/inc/ani_mac.h @@ -27,8 +27,14 @@ public: ~MacImpl(); void InitSync(weak::SymKey key); + void InitWithCallback(weak::SymKey key); + void InitReturnsPromise(weak::SymKey key); void UpdateSync(DataBlob const& input); + void UpdateWithCallback(DataBlob const& input); + void UpdateReturnsPromise(DataBlob const& input); DataBlob DoFinalSync(); + DataBlob DoFinalWithCallback(); + DataBlob DoFinalReturnsPromise(); int32_t GetMacLength(); string GetAlgName(); diff --git a/frameworks/js/ani/inc/ani_md.h b/frameworks/js/ani/inc/ani_md.h index 446eb88..ac566bd 100644 --- a/frameworks/js/ani/inc/ani_md.h +++ b/frameworks/js/ani/inc/ani_md.h @@ -27,7 +27,11 @@ public: ~MdImpl(); void UpdateSync(DataBlob const& input); + void UpdateWithCallback(DataBlob const& input); + void UpdateReturnsPromise(DataBlob const& input); DataBlob DigestSync(); + DataBlob DigestWithCallback(); + DataBlob DigestReturnsPromise(); int32_t GetMdLength(); string GetAlgName(); diff --git a/frameworks/js/ani/inc/ani_sign.h b/frameworks/js/ani/inc/ani_sign.h index 4a80100..bcf740d 100644 --- a/frameworks/js/ani/inc/ani_sign.h +++ b/frameworks/js/ani/inc/ani_sign.h @@ -27,7 +27,11 @@ public: ~SignImpl(); void InitSync(weak::PriKey priKey); + void InitWithCallback(weak::PriKey priKey); + void InitReturnsPromise(weak::PriKey priKey); void UpdateSync(DataBlob const& data); + void UpdateWithCallback(DataBlob const& data); + void UpdateReturnsPromise(DataBlob const& data); DataBlob SignSync(OptDataBlob const& data); void SetSignSpec(ThSignSpecItem itemType, OptIntUint8Arr const& itemValue); OptStrInt GetSignSpec(ThSignSpecItem itemType); diff --git a/frameworks/js/ani/inc/ani_sym_key_generator.h b/frameworks/js/ani/inc/ani_sym_key_generator.h index 026f6a0..14440a8 100644 --- a/frameworks/js/ani/inc/ani_sym_key_generator.h +++ b/frameworks/js/ani/inc/ani_sym_key_generator.h @@ -27,7 +27,11 @@ public: ~SymKeyGeneratorImpl(); SymKey GenerateSymKeySync(); + SymKey GenerateSymKeyWithCallback(); + SymKey GenerateSymKeyReturnsPromise(); SymKey ConvertKeySync(DataBlob const& key); + SymKey ConvertKeyWithKeyCallback(DataBlob const& key); + SymKey ConvertKeyWithKeyReturnsPromise(DataBlob const& key); string GetAlgName(); private: diff --git a/frameworks/js/ani/inc/ani_verify.h b/frameworks/js/ani/inc/ani_verify.h index acaa123..de91964 100644 --- a/frameworks/js/ani/inc/ani_verify.h +++ b/frameworks/js/ani/inc/ani_verify.h @@ -27,8 +27,14 @@ public: ~VerifyImpl(); void InitSync(weak::PubKey pubKey); + void InitWithCallback(weak::PubKey pubKey); + void InitReturnsPromise(weak::PubKey pubKey); void UpdateSync(DataBlob const& input); + void UpdateWithCallback(DataBlob const& input); + void UpdateReturnsPromise(DataBlob const& input); bool VerifySync(OptDataBlob const& data, DataBlob const& signature); + bool VerifyWithCallback(OptDataBlob const& data, DataBlob const& signature); + bool VerifyReturnsPromise(OptDataBlob const& data, DataBlob const& signature); OptDataBlob RecoverSync(DataBlob const& signature); void SetVerifySpec(ThSignSpecItem itemType, OptIntUint8Arr const& itemValue); OptStrInt GetVerifySpec(ThSignSpecItem itemType); diff --git a/frameworks/js/ani/src/ani_asy_key_generator.cpp b/frameworks/js/ani/src/ani_asy_key_generator.cpp index be9470d..c988a04 100644 --- a/frameworks/js/ani/src/ani_asy_key_generator.cpp +++ b/frameworks/js/ani/src/ani_asy_key_generator.cpp @@ -70,6 +70,16 @@ KeyPair AsyKeyGeneratorImpl::GenerateKeyPairSync() return make_holder(keyPair); } +KeyPair AsyKeyGeneratorImpl::GenerateKeyPairWithCallback() +{ + return this->GenerateKeyPairSync(); +} + +KeyPair AsyKeyGeneratorImpl::GenerateKeyPairReturnsPromise() +{ + return this->GenerateKeyPairSync(); +} + KeyPair AsyKeyGeneratorImpl::ConvertKeySync(OptDataBlob const& pubKey, OptDataBlob const& priKey) { if (this->generator_ == nullptr) { @@ -97,6 +107,17 @@ KeyPair AsyKeyGeneratorImpl::ConvertKeySync(OptDataBlob const& pubKey, OptDataBl return make_holder(keyPair); } +KeyPair AsyKeyGeneratorImpl::ConvertKeyWithPubKeyPriKeyCallback(OptDataBlob const& pubKey, OptDataBlob const& priKey) +{ + return this->ConvertKeySync(pubKey, priKey); +} + +KeyPair AsyKeyGeneratorImpl::ConvertKeyWithPubKeyPriKeyReturnsPromise(OptDataBlob const& pubKey, + OptDataBlob const& priKey) +{ + return this->ConvertKeySync(pubKey, priKey); +} + KeyPair AsyKeyGeneratorImpl::ConvertPemKeySync(OptString const& pubKey, OptString const& priKey) { return ConvertPemKeyInner(this->generator_, nullptr, pubKey, priKey); diff --git a/frameworks/js/ani/src/ani_asy_key_generator_by_spec.cpp b/frameworks/js/ani/src/ani_asy_key_generator_by_spec.cpp index e79c693..47f29a0 100644 --- a/frameworks/js/ani/src/ani_asy_key_generator_by_spec.cpp +++ b/frameworks/js/ani/src/ani_asy_key_generator_by_spec.cpp @@ -432,6 +432,16 @@ KeyPair AsyKeyGeneratorBySpecImpl::GenerateKeyPairSync() return make_holder(keyPair); } +KeyPair AsyKeyGeneratorBySpecImpl::GenerateKeyPairWithCallback() +{ + return this->GenerateKeyPairSync(); +} + +KeyPair AsyKeyGeneratorBySpecImpl::GenerateKeyPairReturnsPromise() +{ + return this->GenerateKeyPairSync(); +} + PriKey AsyKeyGeneratorBySpecImpl::GeneratePriKeySync() { if (this->generator_ == nullptr) { diff --git a/frameworks/js/ani/src/ani_cipher.cpp b/frameworks/js/ani/src/ani_cipher.cpp index e4495de..c6ca034 100644 --- a/frameworks/js/ani/src/ani_cipher.cpp +++ b/frameworks/js/ani/src/ani_cipher.cpp @@ -153,6 +153,16 @@ void CipherImpl::InitSync(CryptoMode opMode, weak::Key key, OptParamsSpec const& } } +void CipherImpl::InitWithCallback(CryptoMode opMode, weak::Key key, OptParamsSpec const& params) +{ + return this->InitSync(opMode, key, params); +} + +void CipherImpl::InitReturnsPromise(CryptoMode opMode, weak::Key key, OptParamsSpec const& params) +{ + return this->InitSync(opMode, key, params); +} + DataBlob CipherImpl::UpdateSync(DataBlob const& input) { if (this->cipher_ == nullptr) { @@ -173,6 +183,16 @@ DataBlob CipherImpl::UpdateSync(DataBlob const& input) return { data }; } +DataBlob CipherImpl::UpdateWithCallback(DataBlob const& input) +{ + return this->UpdateSync(input); +} + +DataBlob CipherImpl::UpdateReturnsPromise(DataBlob const& input) +{ + return this->UpdateSync(input); +} + DataBlob CipherImpl::DoFinalSync(OptDataBlob const& input) { if (this->cipher_ == nullptr) { @@ -197,6 +217,16 @@ DataBlob CipherImpl::DoFinalSync(OptDataBlob const& input) return { data }; } +DataBlob CipherImpl::DoFinalWithDataCallback(OptDataBlob const& input) +{ + return this->DoFinalSync(input); +} + +DataBlob CipherImpl::DoFinalWithDataReturnsPromise(OptDataBlob const& input) +{ + return this->DoFinalSync(input); +} + void CipherImpl::SetCipherSpec(ThCipherSpecItem itemType, array_view itemValue) { if (this->cipher_ == nullptr) { diff --git a/frameworks/js/ani/src/ani_mac.cpp b/frameworks/js/ani/src/ani_mac.cpp index 0c9ea47..1f281ea 100644 --- a/frameworks/js/ani/src/ani_mac.cpp +++ b/frameworks/js/ani/src/ani_mac.cpp @@ -60,6 +60,16 @@ void MacImpl::InitSync(weak::SymKey key) } } +void MacImpl::InitWithCallback(weak::SymKey key) +{ + return this->InitSync(key); +} + +void MacImpl::InitReturnsPromise(weak::SymKey key) +{ + return this->InitSync(key); +} + void MacImpl::UpdateSync(DataBlob const& input) { if (this->mac_ == nullptr) { @@ -75,6 +85,16 @@ void MacImpl::UpdateSync(DataBlob const& input) } } +void MacImpl::UpdateWithCallback(DataBlob const& input) +{ + return this->UpdateSync(input); +} + +void MacImpl::UpdateReturnsPromise(DataBlob const& input) +{ + return this->UpdateSync(input); +} + DataBlob MacImpl::DoFinalSync() { if (this->mac_ == nullptr) { @@ -93,6 +113,16 @@ DataBlob MacImpl::DoFinalSync() return { data }; } +DataBlob MacImpl::DoFinalWithCallback() +{ + return this->DoFinalSync(); +} + +DataBlob MacImpl::DoFinalReturnsPromise() +{ + return this->DoFinalSync(); +} + int32_t MacImpl::GetMacLength() { if (this->mac_ == nullptr) { @@ -113,7 +143,7 @@ string MacImpl::GetAlgName() return (algName == nullptr) ? "" : string(algName); } -Mac CreateMacByStr(string_view algName) +Mac CreateMacWithAlgName(string_view algName) { HcfHmacParamsSpec spec = {}; spec.base.algName = HMAC_ALG_NAME.c_str(); @@ -121,7 +151,7 @@ Mac CreateMacByStr(string_view algName) return CreateMacInner(reinterpret_cast(&spec)); } -Mac CreateMacBySpec(OptExtMacSpec const& macSpec) +Mac CreateMacWithMacSpec(OptExtMacSpec const& macSpec) { HcfMacParamsSpec *spec = nullptr; HcfHmacParamsSpec hmacSpec = {}; @@ -145,6 +175,6 @@ Mac CreateMacBySpec(OptExtMacSpec const& macSpec) // Since these macros are auto-generate, lint will cause false positive. // NOLINTBEGIN -TH_EXPORT_CPP_API_CreateMacByStr(ANI::CryptoFramework::CreateMacByStr); -TH_EXPORT_CPP_API_CreateMacBySpec(ANI::CryptoFramework::CreateMacBySpec); +TH_EXPORT_CPP_API_CreateMacWithAlgName(ANI::CryptoFramework::CreateMacWithAlgName); +TH_EXPORT_CPP_API_CreateMacWithMacSpec(ANI::CryptoFramework::CreateMacWithMacSpec); // NOLINTEND diff --git a/frameworks/js/ani/src/ani_md.cpp b/frameworks/js/ani/src/ani_md.cpp index d2efc23..4c7153b 100644 --- a/frameworks/js/ani/src/ani_md.cpp +++ b/frameworks/js/ani/src/ani_md.cpp @@ -41,6 +41,16 @@ void MdImpl::UpdateSync(DataBlob const& input) } } +void MdImpl::UpdateWithCallback(DataBlob const& input) +{ + return this->UpdateSync(input); +} + +void MdImpl::UpdateReturnsPromise(DataBlob const& input) +{ + return this->UpdateSync(input); +} + DataBlob MdImpl::DigestSync() { if (this->md_ == nullptr) { @@ -59,6 +69,16 @@ DataBlob MdImpl::DigestSync() return { data }; } +DataBlob MdImpl::DigestWithCallback() +{ + return this->DigestSync(); +} + +DataBlob MdImpl::DigestReturnsPromise() +{ + return this->DigestSync(); +} + int32_t MdImpl::GetMdLength() { if (this->md_ == nullptr) { diff --git a/frameworks/js/ani/src/ani_sign.cpp b/frameworks/js/ani/src/ani_sign.cpp index 7cb1930..b3c9101 100644 --- a/frameworks/js/ani/src/ani_sign.cpp +++ b/frameworks/js/ani/src/ani_sign.cpp @@ -88,6 +88,16 @@ void SignImpl::InitSync(weak::PriKey priKey) } } +void SignImpl::InitWithCallback(weak::PriKey priKey) +{ + return this->InitSync(priKey); +} + +void SignImpl::InitReturnsPromise(weak::PriKey priKey) +{ + return this->InitSync(priKey); +} + void SignImpl::UpdateSync(DataBlob const& data) { if (this->sign_ == nullptr) { @@ -103,6 +113,16 @@ void SignImpl::UpdateSync(DataBlob const& data) } } +void SignImpl::UpdateWithCallback(DataBlob const& data) +{ + return this->UpdateSync(data); +} + +void SignImpl::UpdateReturnsPromise(DataBlob const& data) +{ + return this->UpdateSync(data); +} + DataBlob SignImpl::SignSync(OptDataBlob const& data) { if (this->sign_ == nullptr) { diff --git a/frameworks/js/ani/src/ani_sym_key_generator.cpp b/frameworks/js/ani/src/ani_sym_key_generator.cpp index 0273301..fe9fd41 100644 --- a/frameworks/js/ani/src/ani_sym_key_generator.cpp +++ b/frameworks/js/ani/src/ani_sym_key_generator.cpp @@ -42,6 +42,16 @@ SymKey SymKeyGeneratorImpl::GenerateSymKeySync() return make_holder(symKey); } +SymKey SymKeyGeneratorImpl::GenerateSymKeyWithCallback() +{ + return this->GenerateSymKeySync(); +} + +SymKey SymKeyGeneratorImpl::GenerateSymKeyReturnsPromise() +{ + return this->GenerateSymKeySync(); +} + SymKey SymKeyGeneratorImpl::ConvertKeySync(DataBlob const& key) { if (this->generator_ == nullptr) { @@ -59,6 +69,16 @@ SymKey SymKeyGeneratorImpl::ConvertKeySync(DataBlob const& key) return make_holder(symKey); } +SymKey SymKeyGeneratorImpl::ConvertKeyWithKeyCallback(DataBlob const& key) +{ + return this->ConvertKeySync(key); +} + +SymKey SymKeyGeneratorImpl::ConvertKeyWithKeyReturnsPromise(DataBlob const& key) +{ + return this->ConvertKeySync(key); +} + string SymKeyGeneratorImpl::GetAlgName() { if (this->generator_ == nullptr) { diff --git a/frameworks/js/ani/src/ani_verify.cpp b/frameworks/js/ani/src/ani_verify.cpp index fb2a772..1c0ebb0 100644 --- a/frameworks/js/ani/src/ani_verify.cpp +++ b/frameworks/js/ani/src/ani_verify.cpp @@ -89,6 +89,16 @@ void VerifyImpl::InitSync(weak::PubKey pubKey) } } +void VerifyImpl::InitWithCallback(weak::PubKey pubKey) +{ + return this->InitSync(pubKey); +} + +void VerifyImpl::InitReturnsPromise(weak::PubKey pubKey) +{ + return this->InitSync(pubKey); +} + void VerifyImpl::UpdateSync(DataBlob const& input) { if (this->verify_ == nullptr) { @@ -104,6 +114,16 @@ void VerifyImpl::UpdateSync(DataBlob const& input) } } +void VerifyImpl::UpdateWithCallback(DataBlob const& input) +{ + return this->UpdateSync(input); +} + +void VerifyImpl::UpdateReturnsPromise(DataBlob const& input) +{ + return this->UpdateSync(input); +} + bool VerifyImpl::VerifySync(OptDataBlob const& data, DataBlob const& signature) { if (this->verify_ == nullptr) { @@ -126,6 +146,16 @@ bool VerifyImpl::VerifySync(OptDataBlob const& data, DataBlob const& signature) return true; } +bool VerifyImpl::VerifyWithCallback(OptDataBlob const& data, DataBlob const& signature) +{ + return this->VerifySync(data, signature); +} + +bool VerifyImpl::VerifyReturnsPromise(OptDataBlob const& data, DataBlob const& signature) +{ + return this->VerifySync(data, signature); +} + OptDataBlob VerifyImpl::RecoverSync(DataBlob const& signature) { if (this->verify_ == nullptr) { diff --git a/frameworks/js/ani/src/impl/ohos.security.cryptoFramework.cryptoFramework.impl.cpp b/frameworks/js/ani/src/impl/ohos.security.cryptoFramework.cryptoFramework.impl.cpp index 375b8f6..38d83b8 100644 --- a/frameworks/js/ani/src/impl/ohos.security.cryptoFramework.cryptoFramework.impl.cpp +++ b/frameworks/js/ani/src/impl/ohos.security.cryptoFramework.cryptoFramework.impl.cpp @@ -34,10 +34,26 @@ public: TH_THROW(std::runtime_error, "UpdateSync not implemented"); } + void UpdateWithCallback(DataBlob const& input) { + return this->UpdateSync(input); + } + + void UpdateReturnsPromise(DataBlob const& input) { + return this->UpdateSync(input); + } + DataBlob DigestSync() { TH_THROW(std::runtime_error, "DigestSync not implemented"); } + DataBlob DigestWithCallback() { + return this->DigestSync(); + } + + DataBlob DigestReturnsPromise() { + return this->DigestSync(); + } + int32_t GetMdLength() { TH_THROW(std::runtime_error, "GetMdLength not implemented"); } @@ -76,14 +92,38 @@ public: TH_THROW(std::runtime_error, "InitSync not implemented"); } + void InitWithCallback(weak::SymKey key) { + return this->InitSync(key); + } + + void InitReturnsPromise(weak::SymKey key) { + return this->InitSync(key); + } + void UpdateSync(DataBlob const& input) { TH_THROW(std::runtime_error, "UpdateSync not implemented"); } + void UpdateWithCallback(DataBlob const& input) { + return this->UpdateSync(input); + } + + void UpdateReturnsPromise(DataBlob const& input) { + return this->UpdateSync(input); + } + DataBlob DoFinalSync() { TH_THROW(std::runtime_error, "DoFinalSync not implemented"); } + DataBlob DoFinalWithCallback() { + return this->DoFinalSync(); + } + + DataBlob DoFinalReturnsPromise() { + return this->DoFinalSync(); + } + int32_t GetMacLength() { TH_THROW(std::runtime_error, "GetMacLength not implemented"); } @@ -264,12 +304,32 @@ public: return make_holder(); } + SymKey GenerateSymKeyWithCallback() { + return this->GenerateSymKeySync(); + } + + SymKey GenerateSymKeyReturnsPromise() { + return this->GenerateSymKeySync(); + } + SymKey ConvertKeySync(DataBlob const& key) { // The parameters in the make_holder function should be of the same type // as the parameters in the constructor of the actual implementation class. return make_holder(); } + SymKey ConvertKeyWithKeyCallback(DataBlob const& key) { + // The parameters in the make_holder function should be of the same type + // as the parameters in the constructor of the actual implementation class. + return this->ConvertKeySync(key); + } + + SymKey ConvertKeyWithKeyReturnsPromise(DataBlob const& key) { + // The parameters in the make_holder function should be of the same type + // as the parameters in the constructor of the actual implementation class. + return this->ConvertKeySync(key); + } + string GetAlgName() { TH_THROW(std::runtime_error, "GetAlgName not implemented"); } @@ -287,12 +347,32 @@ public: return make_holder(); } + KeyPair GenerateKeyPairWithCallback() { + return this->GenerateKeyPairSync(); + } + + KeyPair GenerateKeyPairReturnsPromise() { + return this->GenerateKeyPairSync(); + } + KeyPair ConvertKeySync(OptDataBlob const& pubKey, OptDataBlob const& priKey) { // The parameters in the make_holder function should be of the same type // as the parameters in the constructor of the actual implementation class. return make_holder(); } + KeyPair ConvertKeyWithPubKeyPriKeyCallback(OptDataBlob const& pubKey, OptDataBlob const& priKey) { + // The parameters in the make_holder function should be of the same type + // as the parameters in the constructor of the actual implementation class. + return this->ConvertKeySync(pubKey, priKey); + } + + KeyPair ConvertKeyWithPubKeyPriKeyReturnsPromise(OptDataBlob const& pubKey, OptDataBlob const& priKey) { + // The parameters in the make_holder function should be of the same type + // as the parameters in the constructor of the actual implementation class. + return this->ConvertKeySync(pubKey, priKey); + } + KeyPair ConvertPemKeySync(OptString const& pubKey, OptString const& priKey) { // The parameters in the make_holder function should be of the same type // as the parameters in the constructor of the actual implementation class. @@ -335,14 +415,38 @@ public: TH_THROW(std::runtime_error, "InitSync not implemented"); } + void InitWithCallback(CryptoMode opMode, weak::Key key, OptParamsSpec const& params) { + return this->InitSync(opMode, key, params); + } + + void InitReturnsPromise(CryptoMode opMode, weak::Key key, OptParamsSpec const& params) { + return this->InitSync(opMode, key, params); + } + DataBlob UpdateSync(DataBlob const& input) { TH_THROW(std::runtime_error, "UpdateSync not implemented"); } + DataBlob UpdateWithCallback(DataBlob const& input) { + return this->UpdateSync(input); + } + + DataBlob UpdateReturnsPromise(DataBlob const& input) { + return this->UpdateSync(input); + } + DataBlob DoFinalSync(OptDataBlob const& input) { TH_THROW(std::runtime_error, "DoFinalSync not implemented"); } + DataBlob DoFinalWithDataCallback(OptDataBlob const& input) { + return this->DoFinalSync(input); + } + + DataBlob DoFinalWithDataReturnsPromise(OptDataBlob const& input) { + return this->DoFinalSync(input); + } + void SetCipherSpec(CipherSpecItem itemType, array_view itemValue) { TH_THROW(std::runtime_error, "SetCipherSpec not implemented"); } @@ -366,14 +470,38 @@ public: TH_THROW(std::runtime_error, "InitSync not implemented"); } + void InitWithCallback(weak::PubKey pubKey) { + return this->InitSync(pubKey); + } + + void InitReturnsPromise(weak::PubKey pubKey) { + return this->InitSync(pubKey); + } + void UpdateSync(DataBlob const& input) { TH_THROW(std::runtime_error, "UpdateSync not implemented"); } + void UpdateWithCallback(DataBlob const& input) { + return this->UpdateSync(input); + } + + void UpdateReturnsPromise(DataBlob const& input) { + return this->UpdateSync(input); + } + bool VerifySync(OptDataBlob const& data, DataBlob const& signature) { TH_THROW(std::runtime_error, "VerifySync not implemented"); } + bool VerifyWithCallback(OptDataBlob const& data, DataBlob const& signature) { + return this->VerifySync(data, signature); + } + + bool VerifyReturnsPromise(OptDataBlob const& data, DataBlob const& signature) { + return this->VerifySync(data, signature); + } + OptDataBlob RecoverSync(DataBlob const& signature) { TH_THROW(std::runtime_error, "RecoverSync not implemented"); } @@ -401,10 +529,26 @@ public: TH_THROW(std::runtime_error, "InitSync not implemented"); } + void InitWithCallback(weak::PriKey priKey) { + return this->InitSync(priKey); + } + + void InitReturnsPromise(weak::PriKey priKey) { + return this->InitSync(priKey); + } + void UpdateSync(DataBlob const& data) { TH_THROW(std::runtime_error, "UpdateSync not implemented"); } + void UpdateWithCallback(DataBlob const& data) { + return this->UpdateSync(data); + } + + void UpdateReturnsPromise(DataBlob const& data) { + return this->UpdateSync(data); + } + DataBlob SignSync(OptDataBlob const& data) { TH_THROW(std::runtime_error, "SignSync not implemented"); } @@ -434,6 +578,14 @@ public: return make_holder(); } + KeyPair GenerateKeyPairWithCallback() { + return this->GenerateKeyPairSync(); + } + + KeyPair GenerateKeyPairReturnsPromise() { + return this->GenerateKeyPairSync(); + } + PriKey GeneratePriKeySync() { // The parameters in the make_holder function should be of the same type // as the parameters in the constructor of the actual implementation class. @@ -506,13 +658,13 @@ Random CreateRandom() { return make_holder(); } -Mac CreateMacByStr(string_view algName) { +Mac CreateMacWithAlgName(string_view algName) { // The parameters in the make_holder function should be of the same type // as the parameters in the constructor of the actual implementation class. return make_holder(); } -Mac CreateMacBySpec(OptExtMacSpec const& macSpec) { +Mac CreateMacWithMacSpec(OptExtMacSpec const& macSpec) { // The parameters in the make_holder function should be of the same type // as the parameters in the constructor of the actual implementation class. return make_holder(); @@ -603,8 +755,8 @@ array GenEccSignature(EccSignatureSpec const& spec) { // NOLINTBEGIN TH_EXPORT_CPP_API_CreateMd(CreateMd); TH_EXPORT_CPP_API_CreateRandom(CreateRandom); -TH_EXPORT_CPP_API_CreateMacByStr(CreateMacByStr); -TH_EXPORT_CPP_API_CreateMacBySpec(CreateMacBySpec); +TH_EXPORT_CPP_API_CreateMacWithAlgName(CreateMacWithAlgName); +TH_EXPORT_CPP_API_CreateMacWithMacSpec(CreateMacWithMacSpec); TH_EXPORT_CPP_API_CreateSymKeyGenerator(CreateSymKeyGenerator); TH_EXPORT_CPP_API_CreateAsyKeyGenerator(CreateAsyKeyGenerator); TH_EXPORT_CPP_API_CreateKdf(CreateKdf); -- Gitee