cas-typescript-sdk 1.0.47 → 1.0.49

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (86) hide show
  1. package/index.d.ts +141 -0
  2. package/index.darwin-x64.node +0 -0
  3. package/index.js +631 -0
  4. package/index.linux-x64-gnu.node +0 -0
  5. package/index.linux-x64-musl.node +0 -0
  6. package/index.win32-x64-msvc.node +0 -0
  7. package/lib/asymmetric/index.d.ts +3 -0
  8. package/lib/asymmetric/index.js +5 -0
  9. package/lib/digital-signature/index.d.ts +6 -0
  10. package/lib/digital-signature/index.js +11 -0
  11. package/lib/hashers/index.d.ts +5 -0
  12. package/lib/hashers/index.js +11 -0
  13. package/lib/hybrid/index.d.ts +2 -0
  14. package/lib/hybrid/index.js +5 -0
  15. package/lib/index.d.ts +10 -0
  16. package/lib/key_exchange/index.d.ts +3 -0
  17. package/lib/key_exchange/index.js +5 -0
  18. package/lib/message/index.d.ts +2 -0
  19. package/lib/message/index.js +5 -0
  20. package/lib/password-hashers/index.d.ts +6 -0
  21. package/lib/password-hashers/index.js +13 -0
  22. package/lib/signature/index.d.ts +2 -0
  23. package/lib/signature/index.js +5 -0
  24. package/lib/sponges/index.d.ts +2 -0
  25. package/lib/sponges/index.js +5 -0
  26. package/lib/symmetric/index.d.ts +2 -0
  27. package/lib/symmetric/index.js +5 -0
  28. package/package.json +8 -1
  29. package/.github/workflows/main-pr-linux.yml +0 -28
  30. package/.github/workflows/main-pr-windows.yml +0 -28
  31. package/.github/workflows/main-publish.yml +0 -109
  32. package/Cargo.toml +0 -19
  33. package/build.rs +0 -5
  34. package/docs/EXAMPLES.md +0 -138
  35. package/src/asymmetric/cas_ed25519.rs +0 -35
  36. package/src/asymmetric/cas_rsa.rs +0 -32
  37. package/src/digital_signature/sha_256_rsa.rs +0 -40
  38. package/src/digital_signature/sha_512_rsa.rs +0 -40
  39. package/src/digital_signature/types.rs +0 -34
  40. package/src/hashers/blake2.rs +0 -60
  41. package/src/hashers/sha.rs +0 -68
  42. package/src/hybrid/hpke.rs +0 -63
  43. package/src/hybrid/types.rs +0 -15
  44. package/src/key_exchange/types.rs +0 -17
  45. package/src/key_exchange/x25519.rs +0 -25
  46. package/src/lib.rs +0 -47
  47. package/src/message/hmac.rs +0 -21
  48. package/src/password_hashers/argon2.rs +0 -37
  49. package/src/password_hashers/bcrypt.rs +0 -37
  50. package/src/password_hashers/scrypt.rs +0 -36
  51. package/src/sponges/ascon_aead.rs +0 -66
  52. package/src/symmetric/aes.rs +0 -71
  53. package/src-ts/asymmetric/RSAWrapper.ts +0 -59
  54. package/src-ts/digital-signature/digital-siganture-sha-512.ts +0 -40
  55. package/src-ts/digital-signature/digital-signature-base.ts +0 -6
  56. package/src-ts/digital-signature/digital-signature-factory.ts +0 -25
  57. package/src-ts/digital-signature/digital-signaturte-sha-256.ts +0 -41
  58. package/src-ts/hashers/blake2-wrapper.ts +0 -43
  59. package/src-ts/hashers/hasher-base.ts +0 -6
  60. package/src-ts/hashers/hasher-factory.ts +0 -19
  61. package/src-ts/hashers/hasher-type.ts +0 -4
  62. package/src-ts/hashers/sha-wrapper.ts +0 -60
  63. package/src-ts/hybrid/hpke.ts +0 -44
  64. package/src-ts/key_exchange/x25519.ts +0 -23
  65. package/src-ts/message/hmac.ts +0 -26
  66. package/src-ts/password-hashers/argon2-wrapper.ts +0 -31
  67. package/src-ts/password-hashers/bcrypt-wrapper.ts +0 -35
  68. package/src-ts/password-hashers/password-hasher-base.ts +0 -4
  69. package/src-ts/password-hashers/password-hasher-factory.ts +0 -25
  70. package/src-ts/password-hashers/password-hasher-type.ts +0 -5
  71. package/src-ts/password-hashers/scrypt-wrapper.ts +0 -32
  72. package/src-ts/signature/ed25519-wrapper.ts +0 -36
  73. package/src-ts/sponges/ascon-wrapper.ts +0 -72
  74. package/src-ts/symmetric/aes-wrapper.ts +0 -101
  75. package/test-ts/asymmetric.test.spec.ts +0 -15
  76. package/test-ts/digital-signature.test.spec.ts +0 -70
  77. package/test-ts/hasher.test.spec.ts +0 -139
  78. package/test-ts/helpers/array.ts +0 -10
  79. package/test-ts/hmac.test.spec.ts +0 -16
  80. package/test-ts/hybrid.test.spec.ts +0 -23
  81. package/test-ts/insecure-channel.test.spec.ts +0 -55
  82. package/test-ts/key-exchange.test.spec.ts +0 -23
  83. package/test-ts/password-hasher.test.spec.ts +0 -104
  84. package/test-ts/sponges.test.spec.ts +0 -28
  85. package/test-ts/symmetric.test.spec.ts +0 -82
  86. package/tsconfig.json +0 -22
@@ -1,60 +0,0 @@
1
- use cas_lib::hashers::{blake2::CASBlake2, cas_hasher::CASHasher};
2
- use napi_derive::napi;
3
-
4
- #[napi]
5
- pub fn blake2_sha_512(data_to_hash: Vec<u8>) -> Vec<u8> {
6
- return CASBlake2::hash_512(data_to_hash);
7
- }
8
-
9
- #[napi]
10
- pub fn blake2_sha_512_verify(data_to_hash: Vec<u8>, data_to_verify: Vec<u8>) -> bool {
11
- return CASBlake2::verify_512(data_to_hash, data_to_verify);
12
- }
13
-
14
- #[napi]
15
- pub fn blake2_sha_256(data_to_hash: Vec<u8>) -> Vec<u8> {
16
- return CASBlake2::hash_256(data_to_hash);
17
- }
18
-
19
- #[napi]
20
- pub fn blake2_sha_256_verify(data_to_hash: Vec<u8>, data_to_verify: Vec<u8>) -> bool {
21
- return CASBlake2::verify_256(data_to_hash, data_to_verify);
22
- }
23
-
24
- #[test]
25
- pub fn blake2_sha_512_test() {
26
- let data_to_hash = "NotMyDataToHash".as_bytes().to_vec();
27
- let hashed_data = blake2_sha_512(data_to_hash.clone());
28
- assert_ne!(true, hashed_data.eq(&data_to_hash));
29
- }
30
-
31
- #[test]
32
- pub fn blake2_sha_512_verify_fail_test() {
33
- let data_to_hash = "NotMyDataToHash".as_bytes().to_vec();
34
- let _hashed_data = blake2_sha_512(data_to_hash.clone());
35
- let data_to_verify = "NotMyDataToHash2".as_bytes().to_vec();
36
- assert_ne!(true, blake2_sha_512_verify(data_to_hash, data_to_verify));
37
- }
38
-
39
- #[test]
40
- pub fn blake2_sha_256_test() {
41
- let data_to_hash = "NotMyDataToHash".as_bytes().to_vec();
42
- let hashed_data = blake2_sha_256(data_to_hash.clone());
43
- assert_ne!(true, hashed_data.eq(&data_to_hash));
44
- }
45
-
46
- #[test]
47
- pub fn blake2_sha_256_verify_test() {
48
- let data_to_hash = "NotMyDataToHash".as_bytes().to_vec();
49
- let _hashed_data = blake2_sha_256(data_to_hash.clone());
50
- let data_to_verify = "NotMyDataToHash".as_bytes().to_vec();
51
- assert_ne!(true, blake2_sha_256_verify(data_to_hash, data_to_verify));
52
- }
53
-
54
- #[test]
55
- pub fn blake2_sha_256_verify_fail_test() {
56
- let data_to_hash = "NotMyDataToHash".as_bytes().to_vec();
57
- let _hashed_data = blake2_sha_256(data_to_hash.clone());
58
- let data_to_verify = "NotMyDataToHash2".as_bytes().to_vec();
59
- assert_ne!(true, blake2_sha_256_verify(data_to_hash, data_to_verify));
60
- }
@@ -1,68 +0,0 @@
1
- use cas_lib::hashers::{cas_hasher::CASHasher, sha::CASSHA};
2
- use napi_derive::napi;
3
-
4
- #[napi]
5
- pub fn sha_512(data_to_hash: Vec<u8>) -> Vec<u8> {
6
- return <CASSHA as CASHasher>::hash_512(data_to_hash);
7
- }
8
-
9
- #[napi]
10
- pub fn sha_512_verify(data_to_hash: Vec<u8>, data_to_verify: Vec<u8>) -> bool {
11
- return <CASSHA as CASHasher>::verify_512(data_to_hash, data_to_verify);
12
- }
13
-
14
- #[napi]
15
- pub fn sha_256(data_to_hash: Vec<u8>) -> Vec<u8> {
16
- return <CASSHA as CASHasher>::hash_256(data_to_hash);
17
- }
18
-
19
- #[napi]
20
- pub fn sha_256_verify(data_to_hash: Vec<u8>, data_to_verify: Vec<u8>) -> bool {
21
- return <CASSHA as CASHasher>::verify_256(data_to_hash, data_to_verify);
22
- }
23
-
24
- #[test]
25
- pub fn sha_512_test() {
26
- let data_to_hash = "NotMyDataToHash".as_bytes().to_vec();
27
- let hashed_data = sha_512(data_to_hash.clone());
28
- assert_ne!(true, hashed_data.eq(&data_to_hash));
29
- }
30
-
31
- #[test]
32
- pub fn sha_512_verify_test() {
33
- let data_to_hash = "NotMyDataToHash".as_bytes().to_vec();
34
- let hashed_data = sha_512(data_to_hash.clone());
35
- let data_to_verify = "NotMyDataToHash".as_bytes().to_vec();
36
- assert_ne!(true, sha_512_verify(data_to_hash, data_to_verify));
37
- }
38
-
39
- #[test]
40
- pub fn sha_512_verify_fail_test() {
41
- let data_to_hash = "NotMyDataToHash".as_bytes().to_vec();
42
- let _hashed_data = sha_512(data_to_hash.clone());
43
- let data_to_verify = "NotMyDataToHash2".as_bytes().to_vec();
44
- assert_ne!(true, sha_512_verify(data_to_hash, data_to_verify));
45
- }
46
-
47
- #[test]
48
- pub fn sha_256_test() {
49
- let data_to_hash = "NotMyDataToHash".as_bytes().to_vec();
50
- let hashed_data = sha_256(data_to_hash.clone());
51
- assert_ne!(true, hashed_data.eq(&data_to_hash));
52
- }
53
-
54
- #[test]
55
- pub fn sha_256_verify_test() {
56
- let data_to_hash = "NotMyDataToHash".as_bytes().to_vec();
57
- let _hashed_data = sha_256(data_to_hash.clone());
58
- let data_to_verify = "NotMyDataToHash".as_bytes().to_vec();
59
- assert_ne!(true, sha_256_verify(data_to_hash, data_to_verify));
60
- }
61
-
62
- #[test]
63
- pub fn sha_256_verify_fail_test() {
64
- let data_to_hash = "NotMyDataToHash".as_bytes().to_vec();
65
- let _hashed_data = sha_256(data_to_hash.clone());
66
- let data_to_verify = "NotMyDataToHash2".as_bytes().to_vec();
67
- assert_ne!(true, sha_256_verify(data_to_hash, data_to_verify));
68
- }
@@ -1,63 +0,0 @@
1
- use crate::hybrid::types::{HpkeEncryptResult, HpkeKeyResult};
2
- use cas_lib::hybrid::{cas_hybrid::CASHybrid, hpke::CASHPKE};
3
- use napi_derive::napi;
4
-
5
- #[napi]
6
- pub fn hpke_generate_keypair() -> HpkeKeyResult {
7
- let (secret_key, public_key, info_str) = <CASHPKE as CASHybrid>::generate_key_pair();
8
- HpkeKeyResult {
9
- public_key: public_key,
10
- secret_key: secret_key,
11
- info_str: info_str
12
- }
13
- }
14
-
15
- #[napi]
16
- pub fn generate_info_str() -> Vec<u8> {
17
- return <CASHPKE as CASHybrid>::generate_info_str();
18
- }
19
-
20
- #[napi]
21
- pub fn hpke_encrypt(
22
- plaintext: Vec<u8>,
23
- public_key: Vec<u8>,
24
- info_str: Vec<u8>,
25
- ) -> HpkeEncryptResult {
26
- let encrypt_result: (Vec<u8>, Vec<u8>, Vec<u8>) =
27
- <CASHPKE as CASHybrid>::encrypt(plaintext, public_key, info_str);
28
- return HpkeEncryptResult {
29
- tag: encrypt_result.2,
30
- ciphertext: encrypt_result.1,
31
- encapsulated_key: encrypt_result.0,
32
- }
33
- }
34
-
35
- #[napi]
36
- pub fn hpke_decrypt(
37
- ciphertext: Vec<u8>,
38
- private_key: Vec<u8>,
39
- encapped_key: Vec<u8>,
40
- tag: Vec<u8>,
41
- info_str: Vec<u8>,
42
- ) -> Vec<u8> {
43
- return <CASHPKE as CASHybrid>::decrypt(ciphertext, private_key, encapped_key, tag, info_str);
44
- }
45
-
46
- #[test]
47
- pub fn hpke_encrypt_decrypt_test() {
48
- let hpke_keypair = hpke_generate_keypair();
49
- let plaintext = "This is a secret message".as_bytes().to_vec();
50
- let encrypt_result = hpke_encrypt(
51
- plaintext.clone(),
52
- hpke_keypair.public_key,
53
- hpke_keypair.info_str.clone(),
54
- );
55
- let decrypted_plaintext = hpke_decrypt(
56
- encrypt_result.ciphertext,
57
- hpke_keypair.secret_key,
58
- encrypt_result.encapsulated_key,
59
- encrypt_result.tag,
60
- hpke_keypair.info_str,
61
- );
62
- assert_eq!(plaintext, decrypted_plaintext);
63
- }
@@ -1,15 +0,0 @@
1
- use napi_derive::napi;
2
-
3
- #[napi(constructor)]
4
- pub struct HpkeKeyResult {
5
- pub public_key: Vec<u8>,
6
- pub secret_key: Vec<u8>,
7
- pub info_str: Vec<u8>
8
- }
9
-
10
- #[napi(constructor)]
11
- pub struct HpkeEncryptResult {
12
- pub tag: Vec<u8>,
13
- pub ciphertext: Vec<u8>,
14
- pub encapsulated_key: Vec<u8>,
15
- }
@@ -1,17 +0,0 @@
1
- use cas_lib::key_exchange::x25519::X25519SecretPublicKeyResult;
2
- use napi_derive::napi;
3
-
4
- #[napi(constructor)]
5
- pub struct CASx25519SecretPublicKeyResult {
6
- pub public_key: Vec<u8>,
7
- pub secret_key: Vec<u8>,
8
- }
9
-
10
- impl From<X25519SecretPublicKeyResult> for CASx25519SecretPublicKeyResult {
11
- fn from(value: X25519SecretPublicKeyResult) -> Self {
12
- CASx25519SecretPublicKeyResult {
13
- public_key: value.public_key,
14
- secret_key: value.secret_key
15
- }
16
- }
17
- }
@@ -1,25 +0,0 @@
1
- use cas_lib::key_exchange::{cas_key_exchange::CASKeyExchange, x25519::X25519};
2
- use napi_derive::napi;
3
-
4
- use super::types::CASx25519SecretPublicKeyResult;
5
-
6
-
7
- #[napi]
8
- pub fn x25519_generate_secret_and_public_key() -> CASx25519SecretPublicKeyResult {
9
- return <X25519 as CASKeyExchange>::generate_secret_and_public_key().into();
10
- }
11
-
12
- #[napi]
13
- pub fn x25519_diffie_hellman(my_secret_key: Vec<u8>, users_public_key: Vec<u8>) -> Vec<u8> {
14
- return <X25519 as CASKeyExchange>::diffie_hellman(my_secret_key, users_public_key).to_vec();
15
- }
16
-
17
- #[test]
18
- pub fn x25519_diffie_hellman_test() {
19
- let alice = x25519_generate_secret_and_public_key();
20
- let bob = x25519_generate_secret_and_public_key();
21
-
22
- let alice_shared_secret = x25519_diffie_hellman(alice.secret_key, bob.public_key);
23
- let bob_shared_secret = x25519_diffie_hellman(bob.secret_key, alice.public_key);
24
- assert_eq!(true, alice_shared_secret.eq(&bob_shared_secret));
25
- }
package/src/lib.rs DELETED
@@ -1,47 +0,0 @@
1
- use zeroizing_alloc::ZeroAlloc;
2
-
3
- #[global_allocator]
4
- static ALLOC: ZeroAlloc<std::alloc::System> = ZeroAlloc(std::alloc::System);
5
- mod password_hashers {
6
- pub mod argon2;
7
- pub mod bcrypt;
8
- pub mod scrypt;
9
- }
10
-
11
- mod hashers {
12
- pub mod sha;
13
- pub mod blake2;
14
- }
15
-
16
- mod key_exchange {
17
- pub mod x25519;
18
- mod types;
19
- }
20
-
21
- mod symmetric {
22
- pub mod aes;
23
- }
24
-
25
- mod asymmetric {
26
- pub mod cas_rsa;
27
- pub mod cas_ed25519;
28
- }
29
-
30
- mod digital_signature {
31
- pub mod sha_512_rsa;
32
- pub mod sha_256_rsa;
33
- mod types;
34
- }
35
-
36
- mod sponges {
37
- pub mod ascon_aead;
38
- }
39
-
40
- mod message {
41
- pub mod hmac;
42
- }
43
-
44
- mod hybrid {
45
- pub mod hpke;
46
- pub mod types;
47
- }
@@ -1,21 +0,0 @@
1
- use cas_lib::message::{cas_hmac::CASHMAC, hmac::HMAC};
2
- use napi_derive::napi;
3
-
4
- #[napi]
5
- pub fn hmac_sign(key: Vec<u8>, message: Vec<u8>) -> Vec<u8> {
6
- return <HMAC as CASHMAC>::sign(key, message);
7
- }
8
-
9
- #[napi]
10
- pub fn hmac_verify(key: Vec<u8>, message: Vec<u8>, signature: Vec<u8>) -> bool {
11
- return <HMAC as CASHMAC>::verify(key, message, signature);
12
- }
13
-
14
- #[test]
15
- fn hmac_sign_and_verify_test() {
16
- let key = b"ThisIsMyKeyForHmac".to_vec();
17
- let message = b"ThisIsMyMessageToSign".to_vec();
18
- let signature = hmac_sign(key.clone(), message.clone());
19
- let result = hmac_verify(key, message, signature);
20
- assert_eq!(true, result);
21
- }
@@ -1,37 +0,0 @@
1
-
2
- use napi_derive::napi;
3
- use cas_lib::password_hashers::argon2::CASArgon;
4
-
5
- #[napi]
6
- pub fn argon2_hash(password: String) -> String {
7
- return CASArgon::hash_password(password);
8
- }
9
-
10
- #[napi]
11
- pub fn argon2_verify(hashed_password: String, password_to_verify: String) -> bool {
12
- return CASArgon::verify_password(hashed_password, password_to_verify);
13
- }
14
-
15
- #[test]
16
- pub fn argon2_hash_test() {
17
- let password = "ThisIsNotMyPasswolrd".to_string();
18
- let hashed = argon2_hash(password.clone());
19
- assert_ne!(password, hashed);
20
- }
21
-
22
- #[test]
23
- pub fn argon2_verify_test() {
24
- let password = "ThisIsNotMyPasswolrd".to_string();
25
- let hashed = argon2_hash(password.clone());
26
- let verified = argon2_verify(hashed, password);
27
- assert_eq!(true, verified);
28
- }
29
-
30
- #[test]
31
- pub fn argon2_verify_fail_test() {
32
- let password = "ThisIsNotMyPasswolrd".to_string();
33
- let hashed = argon2_hash(password.clone());
34
- let verified = "Nope".to_string();
35
- let verified = argon2_verify(hashed, verified);
36
- assert_eq!(false, verified);
37
- }
@@ -1,37 +0,0 @@
1
- use cas_lib::password_hashers::bcrypt::CASBCrypt;
2
- use cas_lib::password_hashers::cas_password_hasher::CASPasswordHasher;
3
- use napi_derive::napi;
4
-
5
- #[napi]
6
- pub fn bcrypt_hash(password_to_hash: String) -> String {
7
- return <CASBCrypt as CASPasswordHasher>::hash_password(password_to_hash);
8
- }
9
-
10
- #[napi]
11
- pub fn bcrypt_verify(hashed_password: String, password_to_verify: String) -> bool {
12
- return <CASBCrypt as CASPasswordHasher>::verify_password(hashed_password, password_to_verify);
13
- }
14
-
15
- #[test]
16
- pub fn bcrypt_hash_test() {
17
- let password = "ThisIsNotMyPasswolrd".to_string();
18
- let hashed = bcrypt_hash(password.clone());
19
- assert_ne!(password, hashed);
20
- }
21
-
22
- #[test]
23
- pub fn bcrypt_verify_test() {
24
- let password = "ThisIsNotMyPasswolrd".to_string();
25
- let hashed = bcrypt_hash(password.clone());
26
- let verified = bcrypt_verify(hashed, password);
27
- assert_eq!(true, verified);
28
- }
29
-
30
- #[test]
31
- pub fn bcrypt_verify_fail_test() {
32
- let password = "ThisIsNotMyPasswolrd".to_string();
33
- let hashed = bcrypt_hash(password.clone());
34
- let verified = "nope".to_string();
35
- let verified = bcrypt_verify(hashed, verified);
36
- assert_eq!(false, verified);
37
- }
@@ -1,36 +0,0 @@
1
- use cas_lib::password_hashers::{cas_password_hasher::CASPasswordHasher, scrypt::CASScrypt};
2
- use napi_derive::napi;
3
-
4
- #[napi]
5
- pub fn scrypt_hash(password_to_hash: String) -> String {
6
- return <CASScrypt as CASPasswordHasher>::hash_password(password_to_hash);
7
- }
8
-
9
- #[napi]
10
- pub fn scrypt_verify(hashed_password: String, password_to_verify: String) -> bool {
11
- return <CASScrypt as CASPasswordHasher>::verify_password(hashed_password, password_to_verify);
12
- }
13
-
14
- #[test]
15
- pub fn scrypt_hash_test() {
16
- let password = "BadPassword".to_string();
17
- let hashed_password = scrypt_hash(password.clone());
18
- assert_ne!(password, hashed_password);
19
- }
20
-
21
- #[test]
22
- pub fn scrypt_verify_test() {
23
- let password = "BadPassword".to_string();
24
- let hashed_password = scrypt_hash(password.clone());
25
- let verified = scrypt_verify(hashed_password, password);
26
- assert_eq!(true, verified);
27
- }
28
-
29
- #[test]
30
- pub fn scrypt_verify_fail_test() {
31
- let password = "BadPassword".to_string();
32
- let hashed_password = scrypt_hash(password.clone());
33
- let verified = "Nope".to_string();
34
- let verified = scrypt_verify(hashed_password, verified);
35
- assert_eq!(false, verified);
36
- }
@@ -1,66 +0,0 @@
1
-
2
- use cas_lib::sponges::{ascon_aead::AsconAead, cas_ascon_aead::CASAsconAead};
3
- use napi_derive::napi;
4
-
5
- #[napi]
6
- pub fn ascon128_key_generate() -> Vec<u8> {
7
- return <AsconAead as CASAsconAead>::generate_key().to_vec();
8
- }
9
-
10
- #[test]
11
- fn test_ascon128_key_generate() {
12
- let key = ascon128_key_generate();
13
- assert_eq!(key.len(), 16);
14
- }
15
-
16
- #[napi]
17
- pub fn ascon128_nonce_generate() -> Vec<u8> {
18
- return <AsconAead as CASAsconAead>::generate_nonce().to_vec();
19
- }
20
-
21
- #[test]
22
- pub fn test_ascon128_nonce_generate() {
23
- let nonce = ascon128_nonce_generate();
24
- assert_eq!(nonce.len(), 16);
25
- }
26
-
27
- #[napi]
28
- pub fn ascon128_encrypt(key: Vec<u8>, nonce: Vec<u8>, plaintext: Vec<u8>) -> Vec<u8> {
29
- return <AsconAead as CASAsconAead>::encrypt(key, nonce, plaintext);
30
- }
31
-
32
- #[test]
33
- pub fn test_ascon128_encrypt() {
34
- let key = <AsconAead as CASAsconAead>::generate_key();
35
- let nonce = <AsconAead as CASAsconAead>::generate_nonce();
36
- let plaintext = b"Hello, World!";
37
- let ciphertext = ascon128_encrypt(
38
- key.clone().to_vec(),
39
- nonce.clone().to_vec(),
40
- plaintext.to_vec(),
41
- );
42
- assert_ne!(ciphertext, plaintext.to_vec());
43
- }
44
-
45
- #[napi]
46
- pub fn ascon128_decrypt(key: Vec<u8>, nonce: Vec<u8>, ciphertext: Vec<u8>) -> Vec<u8> {
47
- return <AsconAead as CASAsconAead>::decrypt(key, nonce, ciphertext);
48
- }
49
-
50
- #[test]
51
- pub fn test_ascon128_decrypt() {
52
- let key = <AsconAead as CASAsconAead>::generate_key();
53
- let nonce = <AsconAead as CASAsconAead>::generate_nonce();
54
- let plaintext = b"Hello, World!";
55
- let ciphertext = ascon128_encrypt(
56
- key.clone().to_vec(),
57
- nonce.clone().to_vec(),
58
- plaintext.to_vec(),
59
- );
60
- let decrypted = ascon128_decrypt(
61
- key.clone().to_vec(),
62
- nonce.clone().to_vec(),
63
- ciphertext.clone(),
64
- );
65
- assert_eq!(decrypted, plaintext.to_vec());
66
- }
@@ -1,71 +0,0 @@
1
- use cas_lib::symmetric::{aes::{CASAES128, CASAES256}, cas_symmetric_encryption::{CASAES128Encryption, CASAES256Encryption}};
2
- use napi_derive::napi;
3
-
4
- #[napi]
5
- pub fn aes_nonce() -> Vec<u8> {
6
- return <CASAES256 as CASAES256Encryption>::generate_nonce().to_vec();
7
- }
8
-
9
- #[napi]
10
- pub fn aes128_key() -> Vec<u8> {
11
- return <CASAES128 as CASAES128Encryption>::generate_key().to_vec();
12
- }
13
-
14
- #[napi]
15
- pub fn aes256_key() -> Vec<u8> {
16
- return <CASAES256 as CASAES256Encryption>::generate_key().to_vec();
17
- }
18
-
19
- #[napi]
20
- pub fn aes128_encrypt(aes_key: Vec<u8>, nonce: Vec<u8>, plaintext: Vec<u8>) -> Vec<u8> {
21
- <CASAES128 as CASAES128Encryption>::encrypt_plaintext(aes_key, nonce, plaintext)
22
- }
23
-
24
- #[napi]
25
- pub fn aes128_decrypt(aes_key: Vec<u8>, nonce: Vec<u8>, ciphertext: Vec<u8>) -> Vec<u8> {
26
- <CASAES128 as CASAES128Encryption>::decrypt_ciphertext(aes_key, nonce, ciphertext)
27
- }
28
-
29
- #[napi]
30
- pub fn aes256_encrypt(aes_key: Vec<u8>, nonce: Vec<u8>, plaintext: Vec<u8>) -> Vec<u8> {
31
- <CASAES256 as CASAES256Encryption>::encrypt_plaintext(aes_key, nonce, plaintext)
32
- }
33
-
34
- #[napi]
35
- pub fn aes256_decrypt(aes_key: Vec<u8>, nonce: Vec<u8>, ciphertext: Vec<u8>) -> Vec<u8> {
36
- <CASAES256 as CASAES256Encryption>::decrypt_ciphertext(aes_key, nonce, ciphertext)
37
- }
38
-
39
- #[napi]
40
- pub fn aes_256_key_from_x25519_shared_secret(
41
- shared_secret: Vec<u8>,
42
- ) -> Vec<u8> {
43
- return <CASAES256 as CASAES256Encryption>::key_from_x25519_shared_secret(shared_secret).into();
44
- }
45
-
46
- #[napi]
47
- pub fn aes_128_key_from_x25519_shared_secret(
48
- shared_secret: Vec<u8>,
49
- ) -> Vec<u8> {
50
- return <CASAES128 as CASAES128Encryption>::key_from_x25519_shared_secret(shared_secret).into();
51
- }
52
-
53
- #[test]
54
- fn aes128_encrypt_decrypt_test() {
55
- let aes_key = aes128_key();
56
- let nonce = aes_nonce();
57
- let plaintext = b"WelcomeHome".to_vec();
58
- let ciphertext = aes128_encrypt(aes_key.clone(), nonce.clone(), plaintext.clone());
59
- let decrypted_plaintext = aes128_decrypt(aes_key, nonce, ciphertext);
60
- assert_eq!(decrypted_plaintext, plaintext)
61
- }
62
-
63
- #[test]
64
- fn aes256_encrypt_decrypt_test() {
65
- let aes_key = aes256_key();
66
- let nonce = aes_nonce();
67
- let plaintext = b"WelcomeHome".to_vec();
68
- let ciphertext = aes256_encrypt(aes_key.clone(), nonce.clone(), plaintext.clone());
69
- let decrypted_plaintext = aes256_decrypt(aes_key, nonce, ciphertext);
70
- assert_eq!(decrypted_plaintext, plaintext)
71
- }
@@ -1,59 +0,0 @@
1
- import { CASRSAKeyPairResult, generateRsaKeys, signRsa, verifyRsa } from "../../index";
2
-
3
- export class RSAWrapper {
4
-
5
- /**
6
- * Generates an RSA key pair based of parameter sent in 1024, 2048, and 4096 are supported.
7
- * @param keySize
8
- * @returns CASRSAKeyPairResult
9
- */
10
- public generateKeys(keySize: number): CASRSAKeyPairResult {
11
- if (keySize !== 1024 && keySize !== 2048 && keySize !== 4096) {
12
- throw new Error("You must provide an appropriate key size to generate RSA keys");
13
- }
14
- return generateRsaKeys(keySize);
15
- }
16
-
17
- /**
18
- * Encrypts a plaintext byte array with a RSA public key
19
- * @param publicKey
20
- * @param plaintext
21
- * @returns Array<number>
22
- */
23
-
24
- /**
25
- * Signs a byte array with an RSA private key for verification.
26
- * @param privateKey
27
- * @param hash
28
- * @returns Array<number>
29
- */
30
- public sign(privateKey: string, dataToSign: Array<number>): Array<number> {
31
- if (!privateKey) {
32
- throw new Error("You must provide a private key to sign with RSA");
33
- }
34
- if (!dataToSign || dataToSign.length === 0) {
35
- throw new Error("You must provide an allocated hash to sign with RSA");
36
- }
37
- return signRsa(privateKey, dataToSign);
38
- }
39
-
40
- /**
41
- * Verifies signed data by the corresponding private key with an RSA public key.
42
- * @param publicKey
43
- * @param hash
44
- * @param signature
45
- * @returns boolean
46
- */
47
- public verify(publicKey: string, hash: Array<number>, signature: Array<number>): boolean {
48
- if (!publicKey) {
49
- throw new Error("You must provide a public key to verify with RSA");
50
- }
51
- if (!hash || hash.length === 0) {
52
- throw new Error("You must provide an allocated hash to verify with RSA");
53
- }
54
- if (!signature || signature.length === 0) {
55
- throw new Error("You must provide and allocated signature to verify with RSA");
56
- }
57
- return verifyRsa(publicKey, hash, signature);
58
- }
59
- }
@@ -1,40 +0,0 @@
1
- import { CASRSADigitalSignatureResult, CASSHAED25519DalekDigitalSignatureResult, sha512RsaDigitalSignature, sha512RsaVerifyDigitalSignature } from "../../index";
2
- import { IDigitalSignature } from "./digital-signature-base";
3
-
4
- export class DigitalSignatureSHA512Wrapper implements IDigitalSignature {
5
- /**
6
- * Generates and RSA digital signature with SHA3-512
7
- * @param rsa_key_size
8
- * @param data_to_sign
9
- * @returns CASRSADigitalSignatureResult
10
- */
11
- createRsa(rsa_key_size: number, data_to_sign: number[]): CASRSADigitalSignatureResult {
12
- if (rsa_key_size !== 1024 && rsa_key_size !== 2048 && rsa_key_size !== 4096) {
13
- throw new Error("You need to provide an appropriate RSA key size.");
14
- }
15
- if (data_to_sign?.length === 0) {
16
- throw new Error("Must provide allocated data to sign");
17
- }
18
- return sha512RsaDigitalSignature(rsa_key_size, data_to_sign);
19
- }
20
-
21
- /**
22
- * Verifies a digital signature created with the RSA public key.
23
- * @param public_key
24
- * @param data_to_verify
25
- * @param signature
26
- * @returns boolean
27
- */
28
- verifyRSa(public_key: string, data_to_verify: number[], signature: number[]): boolean {
29
- if (!public_key) {
30
- throw new Error("Must provide a public key");
31
- }
32
- if (data_to_verify?.length === 0) {
33
- throw new Error("Must provide an allocated data to verify");
34
- }
35
- if (signature?.length === 0) {
36
- throw new Error("Must provide an allocated signature");
37
- }
38
- return sha512RsaVerifyDigitalSignature(public_key, data_to_verify, signature);
39
- }
40
- }
@@ -1,6 +0,0 @@
1
- import { CASRSADigitalSignatureResult, CASSHAED25519DalekDigitalSignatureResult } from "../../index";
2
-
3
- export interface IDigitalSignature {
4
- createRsa(rsa_key_size: number, data_to_sign: Array<number>): CASRSADigitalSignatureResult;
5
- verifyRSa(public_key: string, data_to_verify: Array<number>, signature: Array<number>): boolean;
6
- }