diff --git a/frameworks/js/ani/BUILD.gn b/frameworks/js/ani/BUILD.gn index f80323909c385362f859380025e8287b25815f6f..ed1262f8493ead8e963864bb3ca4debdb757ebfb 100644 --- a/frameworks/js/ani/BUILD.gn +++ b/frameworks/js/ani/BUILD.gn @@ -87,25 +87,12 @@ generate_static_abc("crypto_framework_ets") { dependencies = [ ":run_taihe" ] } -generate_static_abc("crypto_framework_test") { - base_url = "${framework_path}/js/ani/test" - files = [ - "${framework_path}/js/ani/test/test_main.ets", - "${framework_path}/js/ani/test/test_utils.ets", - ] - is_boot_abc = "True" - device_dst_file = "/system/framework/crypto_framework_test.abc" -} - ohos_prebuilt_etc("crypto_framework_etc") { source = "$target_out_dir/crypto_framework_ets.abc" module_install_dir = "framework" part_name = "$part_name" subsystem_name = "$subsystem_name" - deps = [ - ":crypto_framework_ets", - # ":crypto_framework_test", - ] + deps = [ ":crypto_framework_ets" ] } group("cryptoframework_ani") { diff --git a/frameworks/js/ani/idl/ohos.security.cryptoFramework.cryptoFramework.taihe b/frameworks/js/ani/idl/ohos.security.cryptoFramework.cryptoFramework.taihe index 1eac9e758619b0c06c63a1eae04013a61662a0c6..2baa8eb9b7be2144f2e5291160860b8262b52cd8 100644 --- a/frameworks/js/ani/idl/ohos.security.cryptoFramework.cryptoFramework.taihe +++ b/frameworks/js/ani/idl/ohos.security.cryptoFramework.cryptoFramework.taihe @@ -51,7 +51,7 @@ interface Md { @gen_promise("digest") DigestSync(): DataBlob; GetMdLength(): i32; - @get GetAlgName(): String; + @get("algName") GetAlgName(): String; } function CreateMd(algName: String): Md; @@ -60,7 +60,7 @@ interface Random { @gen_promise("generateRandom") GenerateRandomSync(len: i32): DataBlob; SetSeed(seed: DataBlob): void; - @get GetAlgName(): String; + @get("algName") GetAlgName(): String; } function CreateRandom(): Random; @@ -75,15 +75,15 @@ interface Mac { @gen_promise("doFinal") DoFinalSync(): DataBlob; GetMacLength(): i32; - @get GetAlgName(): String; + @get("algName") GetAlgName(): String; } function CreateMac(algName: String): Mac; interface Key { GetKeyObj(): i64; GetEncoded(): DataBlob; - @get GetFormat(): String; - @get GetAlgName(): String; + @get("format") GetFormat(): String; + @get("algName") GetAlgName(): String; } enum AsyKeySpecEnum: i32 { @@ -125,7 +125,7 @@ struct KeyEncodingConfig { } union OptKeySpec { - BIGINT: @bigint Array; + BIGINT: @bigint Array; STRING: String; INT32: i32; } @@ -138,6 +138,9 @@ interface PriKey: Key { } interface PubKey: Key { + @!sts_inject_into_class(""" + static { loadLibrary("crypto_framework_ani.z"); } + """) GetPubKeyObj(): i64; GetAsyKeySpec(itemType: AsyKeySpecEnum): OptKeySpec; GetEncodedDer(format: String): DataBlob; @@ -145,8 +148,8 @@ interface PubKey: Key { } interface KeyPair { - @get GetPriKey(): PriKey; - @get GetPubKey(): PubKey; + @get("priKey") GetPriKey(): PriKey; + @get("pubKey") GetPubKey(): PubKey; } interface SymKey: Key { @@ -161,7 +164,7 @@ interface SymKeyGenerator { @gen_async("convertKey") @gen_promise("convertKey") ConvertKeySync(key: DataBlob): SymKey; - @get GetAlgName(): String; + @get("algName") GetAlgName(): String; } function CreateSymKeyGenerator(algName: String): SymKeyGenerator; @@ -175,7 +178,7 @@ interface AsyKeyGenerator { @gen_async("convertKeySync") @gen_promise("convertKeySync") ConvertPemKeySync(pubKey: OptString, priKey: OptString, password: Optional): KeyPair; - @get GetAlgName(): String; + @get("algName") GetAlgName(): String; } function CreateAsyKeyGenerator(algName: String): AsyKeyGenerator; @@ -221,7 +224,7 @@ interface Kdf { @gen_async("generateSecret") @gen_promise("generateSecret") GenerateSecretSync(params: OptExtKdfSpec): DataBlob; - @get GetAlgName(): String; + @get("algName") GetAlgName(): String; } function CreateKdf(algName: String): Kdf; @@ -275,7 +278,7 @@ interface Cipher { @gen_async("doFinal") @gen_promise("doFinal") DoFinalSync(input: OptDataBlob): DataBlob; - @get GetAlgName(): String; + @get("algName") GetAlgName(): String; } function CreateCipher(transformation: String): Cipher; @@ -294,6 +297,6 @@ interface Verify { RecoverSync(signature: DataBlob): OptDataBlob; SetVerifySpec(itemType: i32, itemValue: OptIntUint8Arr): void; GetVerifySpec(itemType: i32): OptIntUint8Arr; - @get GetAlgName(): String; + @get("algName") GetAlgName(): String; } function CreateVerify(algName: String): Verify; diff --git a/frameworks/js/ani/inc/ani_asy_key_generator.h b/frameworks/js/ani/inc/ani_asy_key_generator.h index a38e565bc6e7a7a04c31444915a02a8918c92478..b9a41571592a891a87ace4fb9e2351793875a51a 100644 --- a/frameworks/js/ani/inc/ani_asy_key_generator.h +++ b/frameworks/js/ani/inc/ani_asy_key_generator.h @@ -20,9 +20,6 @@ #include "asy_key_generator.h" namespace ANI::CryptoFramework { -using namespace taihe; -using namespace ohos::security::cryptoFramework::cryptoFramework; - class AsyKeyGeneratorImpl { public: AsyKeyGeneratorImpl(); diff --git a/frameworks/js/ani/inc/ani_cipher.h b/frameworks/js/ani/inc/ani_cipher.h index e01bd5ef4131e719d9b24aeb766df1569ae9b95b..593fec558316442545f83132d39645482f368334 100644 --- a/frameworks/js/ani/inc/ani_cipher.h +++ b/frameworks/js/ani/inc/ani_cipher.h @@ -20,9 +20,6 @@ #include "cipher.h" namespace ANI::CryptoFramework { -using namespace taihe; -using namespace ohos::security::cryptoFramework::cryptoFramework; - class CipherImpl { public: CipherImpl(); diff --git a/frameworks/js/ani/inc/ani_common.h b/frameworks/js/ani/inc/ani_common.h index a4498760ba7745fa6ea9192d3914b7c9f69135c5..8567d95e7630b58926504a2014f4287cfabbdd16 100644 --- a/frameworks/js/ani/inc/ani_common.h +++ b/frameworks/js/ani/inc/ani_common.h @@ -27,10 +27,15 @@ #include "memory.h" #include "object_base.h" +namespace ANI::CryptoFramework { +using namespace taihe; +using namespace ohos::security::cryptoFramework::cryptoFramework; + #define ANI_LOGE_THROW(code, msg) \ do { \ LOGE(msg); \ set_business_error(code, msg); \ } while (0) +} // namespace ANI::CryptoFramework #endif // ANI_COMMON_H diff --git a/frameworks/js/ani/inc/ani_kdf.h b/frameworks/js/ani/inc/ani_kdf.h index a788af533a6c1763770847c29e59ac9842205d35..92e78a3e30674be8c77f4bda632b1c1a3b89bacd 100644 --- a/frameworks/js/ani/inc/ani_kdf.h +++ b/frameworks/js/ani/inc/ani_kdf.h @@ -20,9 +20,6 @@ #include "kdf.h" namespace ANI::CryptoFramework { -using namespace taihe; -using namespace ohos::security::cryptoFramework::cryptoFramework; - class KdfImpl { public: KdfImpl(); diff --git a/frameworks/js/ani/inc/ani_key.h b/frameworks/js/ani/inc/ani_key.h index 4e59de39a109155497c1f78bb78b5eb57f1f4b36..3d49d9695dfd5ae3cee888fe1bf888f799d68463 100644 --- a/frameworks/js/ani/inc/ani_key.h +++ b/frameworks/js/ani/inc/ani_key.h @@ -20,9 +20,6 @@ #include "key.h" namespace ANI::CryptoFramework { -using namespace taihe; -using namespace ohos::security::cryptoFramework::cryptoFramework; - class KeyImpl { public: KeyImpl(); diff --git a/frameworks/js/ani/inc/ani_key_pair.h b/frameworks/js/ani/inc/ani_key_pair.h index af3b14f6129c42b7df206487a6b3860265eb7242..246abd50f18ec24da92817d8055af9ffefef6552 100644 --- a/frameworks/js/ani/inc/ani_key_pair.h +++ b/frameworks/js/ani/inc/ani_key_pair.h @@ -20,9 +20,6 @@ #include "key_pair.h" namespace ANI::CryptoFramework { -using namespace taihe; -using namespace ohos::security::cryptoFramework::cryptoFramework; - class KeyPairImpl { public: KeyPairImpl(); diff --git a/frameworks/js/ani/inc/ani_mac.h b/frameworks/js/ani/inc/ani_mac.h index 339ae7bd30ce888bd6aa9ccdd40c44e04eedead0..b795047714332c08a79e31887217a37219f32c1d 100644 --- a/frameworks/js/ani/inc/ani_mac.h +++ b/frameworks/js/ani/inc/ani_mac.h @@ -20,9 +20,6 @@ #include "mac.h" namespace ANI::CryptoFramework { -using namespace taihe; -using namespace ohos::security::cryptoFramework::cryptoFramework; - class MacImpl { public: MacImpl(); diff --git a/frameworks/js/ani/inc/ani_md.h b/frameworks/js/ani/inc/ani_md.h index fb0adc356fddd57fb54e6f217a702421768d39a8..446eb88fa14a1a5bc5be4fc1a15c3bc3d83bd634 100644 --- a/frameworks/js/ani/inc/ani_md.h +++ b/frameworks/js/ani/inc/ani_md.h @@ -20,9 +20,6 @@ #include "md.h" namespace ANI::CryptoFramework { -using namespace taihe; -using namespace ohos::security::cryptoFramework::cryptoFramework; - class MdImpl { public: MdImpl(); diff --git a/frameworks/js/ani/inc/ani_pri_key.h b/frameworks/js/ani/inc/ani_pri_key.h index 26bbf67204f8c72a360181ff6e44043266b67e48..f46231ccc96a2de888f50d9c23597d8dbfcf126d 100644 --- a/frameworks/js/ani/inc/ani_pri_key.h +++ b/frameworks/js/ani/inc/ani_pri_key.h @@ -20,9 +20,6 @@ #include "pri_key.h" namespace ANI::CryptoFramework { -using namespace taihe; -using namespace ohos::security::cryptoFramework::cryptoFramework; - class PriKeyImpl { public: PriKeyImpl(); diff --git a/frameworks/js/ani/inc/ani_pub_key.h b/frameworks/js/ani/inc/ani_pub_key.h index 2bb51ddb9c38e2a2267cefdbc8acebbe538041e9..43ed016b5843e5199060a3e98876b5955c1cb419 100644 --- a/frameworks/js/ani/inc/ani_pub_key.h +++ b/frameworks/js/ani/inc/ani_pub_key.h @@ -20,9 +20,6 @@ #include "pub_key.h" namespace ANI::CryptoFramework { -using namespace taihe; -using namespace ohos::security::cryptoFramework::cryptoFramework; - class PubKeyImpl { public: PubKeyImpl(); diff --git a/frameworks/js/ani/inc/ani_rand.h b/frameworks/js/ani/inc/ani_rand.h index 1a5d1892074b4e59214456d9f19c3c3d9a2ea772..a4d22e33eb76485a1c047613353a1be253f445ee 100644 --- a/frameworks/js/ani/inc/ani_rand.h +++ b/frameworks/js/ani/inc/ani_rand.h @@ -20,9 +20,6 @@ #include "rand.h" namespace ANI::CryptoFramework { -using namespace taihe; -using namespace ohos::security::cryptoFramework::cryptoFramework; - class RandomImpl { public: RandomImpl(); diff --git a/frameworks/js/ani/inc/ani_sym_key.h b/frameworks/js/ani/inc/ani_sym_key.h index f18dce4a2143768e3e0e8e675b5aa8dafb22298e..e1a6210bbe4eeddfdfa877657a92aae210c58fbd 100644 --- a/frameworks/js/ani/inc/ani_sym_key.h +++ b/frameworks/js/ani/inc/ani_sym_key.h @@ -20,9 +20,6 @@ #include "sym_key.h" namespace ANI::CryptoFramework { -using namespace taihe; -using namespace ohos::security::cryptoFramework::cryptoFramework; - class SymKeyImpl { public: SymKeyImpl(); diff --git a/frameworks/js/ani/inc/ani_sym_key_generator.h b/frameworks/js/ani/inc/ani_sym_key_generator.h index ae8ad16d794f0f1ffd118c43fe575735888c936c..026f6a037a92cd7afcf012f94ca620e1649b6da9 100644 --- a/frameworks/js/ani/inc/ani_sym_key_generator.h +++ b/frameworks/js/ani/inc/ani_sym_key_generator.h @@ -20,9 +20,6 @@ #include "sym_key_generator.h" namespace ANI::CryptoFramework { -using namespace taihe; -using namespace ohos::security::cryptoFramework::cryptoFramework; - class SymKeyGeneratorImpl { public: SymKeyGeneratorImpl(); diff --git a/frameworks/js/ani/inc/ani_verify.h b/frameworks/js/ani/inc/ani_verify.h index 32d5bf01d767885c81f0cd780ca91be12e8fae61..12f3b7d2815fcc184bf67c419f66b51080a4d242 100644 --- a/frameworks/js/ani/inc/ani_verify.h +++ b/frameworks/js/ani/inc/ani_verify.h @@ -20,9 +20,6 @@ #include "signature.h" namespace ANI::CryptoFramework { -using namespace taihe; -using namespace ohos::security::cryptoFramework::cryptoFramework; - class VerifyImpl { public: VerifyImpl(); diff --git a/frameworks/js/ani/src/ani_asy_key_generator.cpp b/frameworks/js/ani/src/ani_asy_key_generator.cpp index 55ee64caef5ddd47968dfcb712090eeb37d754a4..8a17812eafd57f759a917251703d9c2342e32579 100644 --- a/frameworks/js/ani/src/ani_asy_key_generator.cpp +++ b/frameworks/js/ani/src/ani_asy_key_generator.cpp @@ -16,10 +16,6 @@ #include "ani_asy_key_generator.h" #include "ani_key_pair.h" -using namespace taihe; -using namespace ohos::security::cryptoFramework::cryptoFramework; -using namespace ANI::CryptoFramework; - namespace ANI::CryptoFramework { AsyKeyGeneratorImpl::AsyKeyGeneratorImpl() {} @@ -107,5 +103,5 @@ AsyKeyGenerator CreateAsyKeyGenerator(string_view algName) // Since these macros are auto-generate, lint will cause false positive. // NOLINTBEGIN -TH_EXPORT_CPP_API_CreateAsyKeyGenerator(CreateAsyKeyGenerator); +TH_EXPORT_CPP_API_CreateAsyKeyGenerator(ANI::CryptoFramework::CreateAsyKeyGenerator); // NOLINTEND diff --git a/frameworks/js/ani/src/ani_cipher.cpp b/frameworks/js/ani/src/ani_cipher.cpp index 936b0f0beef4f3934e03168e83f4784060ee7424..dc6180ddd7bf25dbb235abff6093e07fb4028c59 100644 --- a/frameworks/js/ani/src/ani_cipher.cpp +++ b/frameworks/js/ani/src/ani_cipher.cpp @@ -18,11 +18,9 @@ #include "detailed_gcm_params.h" #include "detailed_ccm_params.h" -using namespace taihe; -using namespace ohos::security::cryptoFramework::cryptoFramework; +namespace { using namespace ANI::CryptoFramework; -namespace { const std::string IV_PARAMS_SPEC = "IvParamsSpec"; const std::string GCM_PARAMS_SPEC = "GcmParamsSpec"; const std::string CCM_PARAMS_SPEC = "CcmParamsSpec"; @@ -184,5 +182,5 @@ Cipher CreateCipher(string_view transformation) // Since these macros are auto-generate, lint will cause false positive. // NOLINTBEGIN -TH_EXPORT_CPP_API_CreateCipher(CreateCipher); +TH_EXPORT_CPP_API_CreateCipher(ANI::CryptoFramework::CreateCipher); // NOLINTEND diff --git a/frameworks/js/ani/src/ani_kdf.cpp b/frameworks/js/ani/src/ani_kdf.cpp index 3aa49499309a700944ca7ee2f4db4277d1a37638..7b55ec5e41b6db690b575da8d27f024843484ec1 100644 --- a/frameworks/js/ani/src/ani_kdf.cpp +++ b/frameworks/js/ani/src/ani_kdf.cpp @@ -18,11 +18,9 @@ #include "detailed_hkdf_params.h" #include "detailed_scrypt_params.h" -using namespace taihe; -using namespace ohos::security::cryptoFramework::cryptoFramework; +namespace { using namespace ANI::CryptoFramework; -namespace { const std::string PBKDF2_ALG_NAME = "PBKDF2"; const std::string HKDF_ALG_NAME = "HKDF"; const std::string SCRYPT_ALG_NAME = "SCRYPT"; @@ -161,5 +159,5 @@ Kdf CreateKdf(string_view algName) // Since these macros are auto-generate, lint will cause false positive. // NOLINTBEGIN -TH_EXPORT_CPP_API_CreateKdf(CreateKdf); +TH_EXPORT_CPP_API_CreateKdf(ANI::CryptoFramework::CreateKdf); // NOLINTEND diff --git a/frameworks/js/ani/src/ani_key.cpp b/frameworks/js/ani/src/ani_key.cpp index cac240521667d4e439ee3a5e44c26eabf9ffb46d..386418c2ad00bb1404867337e2ec6289a1f26226 100644 --- a/frameworks/js/ani/src/ani_key.cpp +++ b/frameworks/js/ani/src/ani_key.cpp @@ -15,10 +15,6 @@ #include "ani_key.h" -using namespace taihe; -using namespace ohos::security::cryptoFramework::cryptoFramework; -using namespace ANI::CryptoFramework; - namespace ANI::CryptoFramework { KeyImpl::KeyImpl() {} diff --git a/frameworks/js/ani/src/ani_key_pair.cpp b/frameworks/js/ani/src/ani_key_pair.cpp index 565824d4de81e2bdd1139fea03da737745eb721e..d47b784de9ab83feaed2937b9d3a8adadf589c55 100644 --- a/frameworks/js/ani/src/ani_key_pair.cpp +++ b/frameworks/js/ani/src/ani_key_pair.cpp @@ -17,10 +17,6 @@ #include "ani_pri_key.h" #include "ani_pub_key.h" -using namespace taihe; -using namespace ohos::security::cryptoFramework::cryptoFramework; -using namespace ANI::CryptoFramework; - namespace ANI::CryptoFramework { KeyPairImpl::KeyPairImpl() {} diff --git a/frameworks/js/ani/src/ani_mac.cpp b/frameworks/js/ani/src/ani_mac.cpp index 6878cb0b122c1d0f3c07647d0e8f6eb3e4c8baef..4410005c851c44f154d903828aafb96bdd28120c 100644 --- a/frameworks/js/ani/src/ani_mac.cpp +++ b/frameworks/js/ani/src/ani_mac.cpp @@ -16,10 +16,6 @@ #include "ani_mac.h" #include "detailed_hmac_params.h" -using namespace taihe; -using namespace ohos::security::cryptoFramework::cryptoFramework; -using namespace ANI::CryptoFramework; - namespace ANI::CryptoFramework { MacImpl::MacImpl() {} @@ -111,5 +107,5 @@ Mac CreateMac(string_view algName) // Since these macros are auto-generate, lint will cause false positive. // NOLINTBEGIN -TH_EXPORT_CPP_API_CreateMac(CreateMac); +TH_EXPORT_CPP_API_CreateMac(ANI::CryptoFramework::CreateMac); // NOLINTEND diff --git a/frameworks/js/ani/src/ani_md.cpp b/frameworks/js/ani/src/ani_md.cpp index 024aacbfe446ecdc4c14d54d50fb444c4aca3d3e..2c1124dd34840eb5ceb283a959194410814d36d0 100644 --- a/frameworks/js/ani/src/ani_md.cpp +++ b/frameworks/js/ani/src/ani_md.cpp @@ -15,10 +15,6 @@ #include "ani_md.h" -using namespace taihe; -using namespace ohos::security::cryptoFramework::cryptoFramework; -using namespace ANI::CryptoFramework; - namespace ANI::CryptoFramework { MdImpl::MdImpl() {} @@ -95,5 +91,5 @@ Md CreateMd(string_view algName) // Since these macros are auto-generate, lint will cause false positive. // NOLINTBEGIN -TH_EXPORT_CPP_API_CreateMd(CreateMd); +TH_EXPORT_CPP_API_CreateMd(ANI::CryptoFramework::CreateMd); // NOLINTEND diff --git a/frameworks/js/ani/src/ani_pri_key.cpp b/frameworks/js/ani/src/ani_pri_key.cpp index 4b92ad37c062830fe4cf0a702e178dc423520087..14e75b83c37fecdf984e167434b2e1fd75c6d30a 100644 --- a/frameworks/js/ani/src/ani_pri_key.cpp +++ b/frameworks/js/ani/src/ani_pri_key.cpp @@ -15,10 +15,6 @@ #include "ani_pri_key.h" -using namespace taihe; -using namespace ohos::security::cryptoFramework::cryptoFramework; -using namespace ANI::CryptoFramework; - namespace ANI::CryptoFramework { PriKeyImpl::PriKeyImpl() {} diff --git a/frameworks/js/ani/src/ani_pub_key.cpp b/frameworks/js/ani/src/ani_pub_key.cpp index 2dfec7a4b624b39bbd7e33a7dcee0dc25380b21c..80507c509dfe070fcf15f4a32e20609528be88a3 100644 --- a/frameworks/js/ani/src/ani_pub_key.cpp +++ b/frameworks/js/ani/src/ani_pub_key.cpp @@ -15,10 +15,6 @@ #include "ani_pub_key.h" -using namespace taihe; -using namespace ohos::security::cryptoFramework::cryptoFramework; -using namespace ANI::CryptoFramework; - namespace ANI::CryptoFramework { PubKeyImpl::PubKeyImpl() {} diff --git a/frameworks/js/ani/src/ani_rand.cpp b/frameworks/js/ani/src/ani_rand.cpp index 6ad9feefc81fe6de63359801d4afff5623e71356..5b4f2795f037cac1b7bb5fc3c6671cf710075cdd 100644 --- a/frameworks/js/ani/src/ani_rand.cpp +++ b/frameworks/js/ani/src/ani_rand.cpp @@ -15,10 +15,6 @@ #include "ani_rand.h" -using namespace taihe; -using namespace ohos::security::cryptoFramework::cryptoFramework; -using namespace ANI::CryptoFramework; - namespace ANI::CryptoFramework { RandomImpl::RandomImpl() {} @@ -85,5 +81,5 @@ Random CreateRandom() // Since these macros are auto-generate, lint will cause false positive. // NOLINTBEGIN -TH_EXPORT_CPP_API_CreateRandom(CreateRandom); +TH_EXPORT_CPP_API_CreateRandom(ANI::CryptoFramework::CreateRandom); // NOLINTEND diff --git a/frameworks/js/ani/src/ani_sym_key.cpp b/frameworks/js/ani/src/ani_sym_key.cpp index 9c4f50eca6b2137ad3f46ae6c1d8f2751d12cc6a..0880c78077dd3061df47cd04c443b2512c5eed92 100644 --- a/frameworks/js/ani/src/ani_sym_key.cpp +++ b/frameworks/js/ani/src/ani_sym_key.cpp @@ -15,10 +15,6 @@ #include "ani_sym_key.h" -using namespace taihe; -using namespace ohos::security::cryptoFramework::cryptoFramework; -using namespace ANI::CryptoFramework; - namespace ANI::CryptoFramework { SymKeyImpl::SymKeyImpl() : symKey_(nullptr) {} diff --git a/frameworks/js/ani/src/ani_sym_key_generator.cpp b/frameworks/js/ani/src/ani_sym_key_generator.cpp index fbdf46c1d991a3d825721be6e3bd2d83baf4acee..7f16f3cbb18834d65d98469acf1f4bbe83a354f2 100644 --- a/frameworks/js/ani/src/ani_sym_key_generator.cpp +++ b/frameworks/js/ani/src/ani_sym_key_generator.cpp @@ -16,10 +16,6 @@ #include "ani_sym_key_generator.h" #include "ani_sym_key.h" -using namespace taihe; -using namespace ohos::security::cryptoFramework::cryptoFramework; -using namespace ANI::CryptoFramework; - namespace ANI::CryptoFramework { SymKeyGeneratorImpl::SymKeyGeneratorImpl() {} @@ -86,5 +82,5 @@ SymKeyGenerator CreateSymKeyGenerator(string_view algName) // Since these macros are auto-generate, lint will cause false positive. // NOLINTBEGIN -TH_EXPORT_CPP_API_CreateSymKeyGenerator(CreateSymKeyGenerator); +TH_EXPORT_CPP_API_CreateSymKeyGenerator(ANI::CryptoFramework::CreateSymKeyGenerator); // NOLINTEND diff --git a/frameworks/js/ani/src/ani_verify.cpp b/frameworks/js/ani/src/ani_verify.cpp index a00c64aeac5d92d8b52a20025aec58011fcdd2c3..87e3672bfe6f62d09ae7bcbf2a23a3dd083c6762 100644 --- a/frameworks/js/ani/src/ani_verify.cpp +++ b/frameworks/js/ani/src/ani_verify.cpp @@ -16,10 +16,6 @@ #include "ani_verify.h" #include "ani_pub_key.h" -using namespace taihe; -using namespace ohos::security::cryptoFramework::cryptoFramework; -using namespace ANI::CryptoFramework; - namespace ANI::CryptoFramework { VerifyImpl::VerifyImpl() {} @@ -120,5 +116,5 @@ Verify CreateVerify(string_view algName) // Since these macros are auto-generate, lint will cause false positive. // NOLINTBEGIN -TH_EXPORT_CPP_API_CreateVerify(CreateVerify); +TH_EXPORT_CPP_API_CreateVerify(ANI::CryptoFramework::CreateVerify); // NOLINTEND diff --git a/frameworks/js/ani/test/build_test.sh b/frameworks/js/ani/test/build_test.sh new file mode 100644 index 0000000000000000000000000000000000000000..0c228f2c3b80e6d89c3a57b681a9af40f9d7f0f4 --- /dev/null +++ b/frameworks/js/ani/test/build_test.sh @@ -0,0 +1,30 @@ +#!/usr/bin/env bash +# Copyright (c) 2025-2025 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +CURRENT_DIR="$(cd "$(dirname "$0")" && pwd)" +ROOT_PATH="$(cd "${CURRENT_DIR}/../../../../../../.." && pwd)" +BASE_PATH="${ROOT_PATH}/base/security/crypto_framework" +TEST_PATH="${BASE_PATH}/frameworks/js/ani/test" +OUT_PATH="${ROOT_PATH}/out/rk3568" +ABC_NAME="crypto_framework_test.abc" + +ES2PANDA="${OUT_PATH}/clang_x64/arkcompiler/ets_frontend/es2panda" +ARK_LINK="${OUT_PATH}/clang_x64/arkcompiler/runtime_core/ark_link" + +cd "${OUT_PATH}/security/crypto_framework" +"${ES2PANDA}" --arktsconfig "${TEST_PATH}/arktsconfig.json" --ets-module +"${ARK_LINK}" --output="${ABC_NAME}" -- "${TEST_PATH}/dist/"* +rm -rf "${TEST_PATH}/dist" + +echo -e "output abc file: \033[1;32m${OUT_PATH}/security/crypto_framework/${ABC_NAME}\033[0m" diff --git a/frameworks/js/ani/test/test_asy_key_generator.ets b/frameworks/js/ani/test/test_asy_key_generator.ets index e6ff25ae43eaefd952aecb034426753c27314697..7765f481930cb00261ada33e16befc8941eac9a1 100644 --- a/frameworks/js/ani/test/test_asy_key_generator.ets +++ b/frameworks/js/ani/test/test_asy_key_generator.ets @@ -13,6 +13,7 @@ * limitations under the License. */ +import { BusinessError } from "@ohos.base"; import cryptoFramework from "@ohos.security.cryptoFramework"; import utils from "./test_utils"; @@ -26,15 +27,27 @@ function testAsyKeyGeneratorSync() { let skStr = utils.uint8ArrayToHexStr(skBlob.data); console.info('generateKeyPair pubKey: ' + pkStr); console.info('generateKeyPair priKey: ' + skStr); - } catch (err) { - console.error("[error] generateKeyPair: " + err); + } catch (err: BusinessError) { + console.error(`[error] generateKeyPair: ${err.code} ${err.message}`); } } - function testAsyKeyConvertKeySync() { +function testAsyKeyConvertKeySync() { try { - let pubKeyArray = new Uint8Array([48, 89, 48, 19, 6, 7, 42, 134, 72, 206, 61, 2, 1, 6, 8, 42, 129, 28, 207, 85, 1, 130, 45, 3, 66, 0, 4, 90, 3, 58, 157, 190, 248, 76, 7, 132, 200, 151, 208, 112, 230, 96, 140, 90, 238, 211, 155, 128, 109, 248, 40, 83, 214, 78, 42, 104, 106, 55, 148, 249, 35, 61, 32, 221, 135, 143, 100, 45, 97, 194, 176, 52, 73, 136, 174, 40, 70, 70, 34, 103, 103, 161, 99, 27, 187, 13, 187, 109, 244, 13, 7]); - let priKeyArray = new Uint8Array([48, 49, 2, 1, 1, 4, 32, 54, 41, 239, 240, 63, 188, 134, 113, 31, 102, 149, 203, 245, 89, 15, 15, 47, 202, 170, 60, 38, 154, 28, 169, 189, 100, 251, 76, 112, 223, 156, 159, 160, 10, 6, 8, 42, 129, 28, 207, 85, 1, 130, 45]); + let pubKeyArray = new Uint8Array([ + 0x30, 0x59, 0x30, 0x13, 0x06, 0x07, 0x2A, 0x86, 0x48, 0xCE, 0x3D, 0x02, 0x01, 0x06, 0x08, 0x2A, + 0x81, 0x1C, 0xCF, 0x55, 0x01, 0x82, 0x2D, 0x03, 0x42, 0x00, 0x04, 0x5A, 0x03, 0x3A, 0x9D, 0xBE, + 0xF8, 0x4C, 0x07, 0x84, 0xC8, 0x97, 0xD0, 0x70, 0xE6, 0x60, 0x8C, 0x5A, 0xEE, 0xD3, 0x9B, 0x80, + 0x6D, 0xF8, 0x28, 0x53, 0xD6, 0x4E, 0x2A, 0x68, 0x6A, 0x37, 0x94, 0xF9, 0x23, 0x3D, 0x20, 0xDD, + 0x87, 0x8F, 0x64, 0x2D, 0x61, 0xC2, 0xB0, 0x34, 0x49, 0x88, 0xAE, 0x28, 0x46, 0x46, 0x22, 0x67, + 0x67, 0xA1, 0x63, 0x1B, 0xBB, 0x0D, 0xBB, 0x6D, 0xF4, 0x0D, 0x07 + ]); + let priKeyArray = new Uint8Array([ + 0x30, 0x31, 0x02, 0x01, 0x01, 0x04, 0x20, 0x36, 0x29, 0xEF, 0xF0, 0x3F, 0xBC, 0x86, 0x71, 0x1F, + 0x66, 0x95, 0xCB, 0xF5, 0x59, 0x0F, 0x0F, 0x2F, 0xCA, 0xAA, 0x3C, 0x26, 0x9A, 0x1C, 0xA9, 0xBD, + 0x64, 0xFB, 0x4C, 0x70, 0xDF, 0x9C, 0x9F, 0xA0, 0x0A, 0x06, 0x08, 0x2A, 0x81, 0x1C, 0xCF, 0x55, + 0x01, 0x82, 0x2D + ]); let pubKeyBlob: cryptoFramework.DataBlob = { data: pubKeyArray }; @@ -49,8 +62,8 @@ function testAsyKeyGeneratorSync() { let skStr = utils.uint8ArrayToHexStr(skBlob.data); console.info('convertPemKey pubKey: ' + pkStr); console.info('convertPemKey priKey: ' + skStr); - } catch (err) { - console.error("[error] convertPemKey: " + err); + } catch (err: BusinessError) { + console.error(`[error] convertPemKey: ${err.code} ${err.message}`); } } diff --git a/frameworks/js/ani/test/test_cipher.ets b/frameworks/js/ani/test/test_cipher.ets index e8c53402f18928dfd03a4c4062b30885001ed2f4..be1da4a6941876f19a777210bcbbdeff4fa5e901 100644 --- a/frameworks/js/ani/test/test_cipher.ets +++ b/frameworks/js/ani/test/test_cipher.ets @@ -13,6 +13,7 @@ * limitations under the License. */ +import { BusinessError } from "@ohos.base"; import cryptoFramework from "@ohos.security.cryptoFramework"; import utils from "./test_utils"; @@ -81,8 +82,8 @@ function aesCipher(algorithm: string, } else { console.error(`${algorithm} failed`); } - } catch (err) { - console.error(`[error] ${algorithm}: ${err}`); + } catch (err: BusinessError) { + console.error(`[error] ${algorithm}: ${err.code} ${err.message}`); } } diff --git a/frameworks/js/ani/test/test_kdf.ets b/frameworks/js/ani/test/test_kdf.ets index 7a707876e507a5859df68165b5d9192e1582f2dc..0efa8994c0d4c7eb733ce40fd81638fd2ebb70b0 100644 --- a/frameworks/js/ani/test/test_kdf.ets +++ b/frameworks/js/ani/test/test_kdf.ets @@ -13,6 +13,7 @@ * limitations under the License. */ +import { BusinessError } from "@ohos.base"; import cryptoFramework from "@ohos.security.cryptoFramework"; import utils from "./test_utils"; @@ -31,8 +32,8 @@ function testPBKDF2Sync() { console.log("PBKDF2 algName: " + kdf.algName); console.info("PBKDF2: " + str); } - catch (err) { - console.error("[error] PBKDF2: " + err); + catch (err: BusinessError) { + console.error(`[error] PBKDF2: ${err.code} ${err.message}`); } } @@ -50,8 +51,8 @@ function testHKDFSync() { let str = utils.uint8ArrayToHexStr(secret.data); console.log("HKDF algName: " + kdf.algName); console.info("HKDF: " + str); - } catch (err) { - console.error("[error] HKDF: " + err); + } catch (err: BusinessError) { + console.error(`[error] HKDF: ${err.code} ${err.message}`); } } @@ -72,8 +73,8 @@ function testScryptSync() { let str = utils.uint8ArrayToHexStr(secret.data); console.log("Scrypt algName: " + kdf.algName); console.info("Scrypt: " + str); - } catch (err) { - console.error("[error] Scrypt: " + err); + } catch (err: BusinessError) { + console.error(`[error] Scrypt: ${err.code} ${err.message}`); } } diff --git a/frameworks/js/ani/test/test_mac.ets b/frameworks/js/ani/test/test_mac.ets index 7aebb47ff6cbbe31552dfbbc1fe862867c85a80f..99006c4d3932d70ea5b2968c3968af42e3f741aa 100644 --- a/frameworks/js/ani/test/test_mac.ets +++ b/frameworks/js/ani/test/test_mac.ets @@ -13,6 +13,7 @@ * limitations under the License. */ +import { BusinessError } from "@ohos.base"; import cryptoFramework from "@ohos.security.cryptoFramework"; import utils from "./test_utils"; @@ -36,8 +37,8 @@ function testMacSync() { console.log("HMAC algName: " + mac.algName); console.log("HMAC-SHA256: " + str); } - catch (err) { - console.error("[error] HMAC-SHA256: " + err); + catch (err: BusinessError) { + console.error(`[error] HMAC-SHA256: ${err.code} ${err.message}`); } } @@ -61,8 +62,8 @@ function testMacAsync() { console.log("HMAC algName: " + mac.algName); console.log("HMAC-SHA256: " + str); } - catch (err) { - console.error("[error] HMAC-SHA256: " + err); + catch (err: BusinessError) { + console.error(`[error] HMAC-SHA256: ${err.code} ${err.message}`); } } diff --git a/frameworks/js/ani/test/test_md.ets b/frameworks/js/ani/test/test_md.ets index 3263177e77834d36268022b7d64f685780a309a7..b37d5898f6a590478294ed04c77cd695e2ff1556 100644 --- a/frameworks/js/ani/test/test_md.ets +++ b/frameworks/js/ani/test/test_md.ets @@ -13,6 +13,7 @@ * limitations under the License. */ +import { BusinessError } from "@ohos.base"; import cryptoFramework from "@ohos.security.cryptoFramework"; import utils from "./test_utils"; @@ -29,8 +30,8 @@ function testMdSync() { console.log("MD5: " + str); let length = md.getMdLength(); console.log("MD5 length: " + length); - } catch (err) { - console.log("[error] MD5: " + err); + } catch (err: BusinessError) { + console.log(`[error] MD5: ${err.code} ${err.message}`); } } @@ -47,8 +48,8 @@ function testMdAsync() { console.log("MD5: " + str); let length = md.getMdLength(); console.log("MD5 length: " + length); - } catch (err) { - console.log("[error] MD5: " + err); + } catch (err: BusinessError) { + console.log(`[error] MD5: ${err.code} ${err.message}`); } } diff --git a/frameworks/js/ani/test/test_rand.ets b/frameworks/js/ani/test/test_rand.ets index c61047917a685bd772e55ae7ea4717ae385d658a..b299f03a3a207fba2decb11b842587c42329aa82 100644 --- a/frameworks/js/ani/test/test_rand.ets +++ b/frameworks/js/ani/test/test_rand.ets @@ -14,6 +14,7 @@ * limitations under the License. */ +import { BusinessError } from "@ohos.base"; import cryptoFramework from "@ohos.security.cryptoFramework"; import utils from "./test_utils"; @@ -28,8 +29,8 @@ function testRandomSync() { let output = random.generateRandomSync(16); let str = utils.uint8ArrayToHexStr(output.data); console.log("Random: " + str); - } catch (err) { - console.error("[error] Random: " + err); + } catch (err: BusinessError) { + console.error(`[error] Random: ${err.code} ${err.message}`); } } diff --git a/frameworks/js/ani/test/test_sym_key_generator.ets b/frameworks/js/ani/test/test_sym_key_generator.ets index d06e8389bda4918905f618d06fd2950803a3deb5..d216e15bf0c9960f63d2741422bc292cddda35ec 100644 --- a/frameworks/js/ani/test/test_sym_key_generator.ets +++ b/frameworks/js/ani/test/test_sym_key_generator.ets @@ -13,6 +13,7 @@ * limitations under the License. */ +import { BusinessError } from "@ohos.base"; import cryptoFramework from "@ohos.security.cryptoFramework"; import utils from "./test_utils"; @@ -23,8 +24,8 @@ function testSymKeyGeneratorSync() { let encodedKey = symKey.getEncoded(); let str = utils.uint8ArrayToHexStr(encodedKey.data); console.log("generateSymKey: " + str); - } catch (err) { - console.error("[error] generateSymKey: " + err); + } catch (err: BusinessError) { + console.error(`[error] generateSymKey: ${err.code} ${err.message}`); } } @@ -38,8 +39,8 @@ function testSymKeyConvertKeySync() { let encodedKey = symKey.getEncoded(); let str = utils.uint8ArrayToHexStr(encodedKey.data); console.log("convertKey: " + str); - } catch (err) { - console.error("[error] convertKey: " + err); + } catch (err: BusinessError) { + console.error(`[error] convertKey: ${err.code} ${err.message}`); } } diff --git a/frameworks/js/ani/test/test_verify.ets b/frameworks/js/ani/test/test_verify.ets index 92605e07543c170c7628944f02d8d1b3c212b3b0..62c2338a168532038a2c710e9835b44e2cb8592a 100644 --- a/frameworks/js/ani/test/test_verify.ets +++ b/frameworks/js/ani/test/test_verify.ets @@ -13,21 +13,27 @@ * limitations under the License. */ +import { BusinessError } from "@ohos.base"; import cryptoFramework from "@ohos.security.cryptoFramework"; import utils from "./test_utils"; function testVerifySync() { try { let keyGenAlg = "SM2_256"; - let pubKeyArray = - new Uint8Array([48, 89, 48, 19, 6, 7, 42, 134, 72, 206, 61, 2, 1, 6, 8, 42, 129, 28, 207, 85, 1, 130, 45, 3, 66, - 0, 4, 90, 3, 58, 157, 190, 248, 76, 7, 132, 200, 151, 208, 112, 230, 96, 140, 90, 238, 211, 155, 128, 109, 248, - 40, 83, 214, 78, 42, 104, 106, 55, 148, 249, 35, 61, 32, 221, 135, 143, 100, 45, 97, 194, 176, 52, 73, 136, 174, - 40, 70, 70, 34, 103, 103, 161, 99, 27, 187, 13, 187, 109, 244, 13, 7]); - let priKeyArray = - new Uint8Array([48, 49, 2, 1, 1, 4, 32, 54, 41, 239, 240, 63, 188, 134, 113, 31, 102, 149, 203, 245, 89, 15, 15, - 47, 202, 170, 60, 38, 154, 28, 169, 189, 100, 251, 76, 112, 223, 156, 159, 160, 10, 6, 8, 42, 129, 28, 207, 85, - 1, 130, 45]); + let pubKeyArray = new Uint8Array([ + 0x30, 0x59, 0x30, 0x13, 0x06, 0x07, 0x2A, 0x86, 0x48, 0xCE, 0x3D, 0x02, 0x01, 0x06, 0x08, 0x2A, + 0x81, 0x1C, 0xCF, 0x55, 0x01, 0x82, 0x2D, 0x03, 0x42, 0x00, 0x04, 0x5A, 0x03, 0x3A, 0x9D, 0xBE, + 0xF8, 0x4C, 0x07, 0x84, 0xC8, 0x97, 0xD0, 0x70, 0xE6, 0x60, 0x8C, 0x5A, 0xEE, 0xD3, 0x9B, 0x80, + 0x6D, 0xF8, 0x28, 0x53, 0xD6, 0x4E, 0x2A, 0x68, 0x6A, 0x37, 0x94, 0xF9, 0x23, 0x3D, 0x20, 0xDD, + 0x87, 0x8F, 0x64, 0x2D, 0x61, 0xC2, 0xB0, 0x34, 0x49, 0x88, 0xAE, 0x28, 0x46, 0x46, 0x22, 0x67, + 0x67, 0xA1, 0x63, 0x1B, 0xBB, 0x0D, 0xBB, 0x6D, 0xF4, 0x0D, 0x07 + ]); + let priKeyArray = new Uint8Array([ + 0x30, 0x31, 0x02, 0x01, 0x01, 0x04, 0x20, 0x36, 0x29, 0xEF, 0xF0, 0x3F, 0xBC, 0x86, 0x71, 0x1F, + 0x66, 0x95, 0xCB, 0xF5, 0x59, 0x0F, 0x0F, 0x2F, 0xCA, 0xAA, 0x3C, 0x26, 0x9A, 0x1C, 0xA9, 0xBD, + 0x64, 0xFB, 0x4C, 0x70, 0xDF, 0x9C, 0x9F, 0xA0, 0x0A, 0x06, 0x08, 0x2A, 0x81, 0x1C, 0xCF, 0x55, + 0x01, 0x82, 0x2D + ]); let pubKeyBlob: cryptoFramework.DataBlob = { data: pubKeyArray }; @@ -36,15 +42,19 @@ function testVerifySync() { }; let generator = cryptoFramework.createAsyKeyGenerator(keyGenAlg); let keyPair = generator.convertKeySync(pubKeyBlob, priKeyBlob); - let signData = - new Uint8Array([48, 69, 2, 32, 97, 0, 41, 250, 12, 72, 62, 173, 60, 144, 101, 117, 249, 72, 50, 121, 191, 216, - 82, 82, 195, 87, 92, 109, 197, 93, 104, 15, 195, 247, 20, 85, 2, 33, 0, 164, 22, 34, 175, 112, 161, 170, 50, - 165, 253, 248, 248, 121, 16, 83, 214, 68, 188, 158, 130, 54, 89, 250, 143, 31, 226, 26, 121, 162, 153, 102, 28]) + let signData = new Uint8Array([ + 0x30, 0x45, 0x02, 0x20, 0x61, 0x00, 0x29, 0xFA, 0x0C, 0x48, 0x3E, 0xAD, 0x3C, 0x90, 0x65, 0x75, + 0xF9, 0x48, 0x32, 0x79, 0xBF, 0xD8, 0x52, 0x52, 0xC3, 0x57, 0x5C, 0x6D, 0xC5, 0x5D, 0x68, 0x0F, + 0xC3, 0xF7, 0x14, 0x55, 0x02, 0x21, 0x00, 0xA4, 0x16, 0x22, 0xAF, 0x70, 0xA1, 0xAA, 0x32, 0xA5, + 0xFD, 0xF8, 0xF8, 0x79, 0x10, 0x53, 0xD6, 0x44, 0xBC, 0x9E, 0x82, 0x36, 0x59, 0xFA, 0x8F, 0x1F, + 0xE2, 0x1A, 0x79, 0xA2, 0x99, 0x66, 0x1C + ]) let signDataBytes: cryptoFramework.DataBlob = { data: signData }; - - let input = new Uint8Array([72,101,108,108,111,32,87,111,114,108,100]); + let input = new Uint8Array([ + 0x48, 0x65, 0x6C, 0x6C, 0x6F, 0x20, 0x57, 0x6F, 0x72, 0x6C, 0x64 + ]); let inputData: cryptoFramework.DataBlob = { data: input }; @@ -53,12 +63,12 @@ function testVerifySync() { verify.updateSync(inputData); let res = verify.verifySync(null, signDataBytes) if (res === true) { - console.info('verify success'); + console.info('Verify success'); } else { - console.error('verify failed'); + console.error('Verify failed'); } - } catch (err) { - console.log("[error] verify: " + err); + } catch (err: BusinessError) { + console.error(`[error] Verify: ${err.code} ${err.message}`); } } diff --git a/interfaces/inner_api/common/blob.h b/interfaces/inner_api/common/blob.h index ff0345038c08e528f60901633575cc3791890428..76ffcbf0a0713c326449ea67d3f3e92dcdbf1f09 100644 --- a/interfaces/inner_api/common/blob.h +++ b/interfaces/inner_api/common/blob.h @@ -25,11 +25,6 @@ struct HcfBlob { size_t len; }; -enum EncodingFormat { - HCF_FORMAT_DER = 0, - HCF_FORMAT_PEM = 1, -}; - #ifdef __cplusplus extern "C" { #endif