MCPcopy Create free account
hub / github.com/NodeDB-Lab/nodedb / encrypt_decrypt_roundtrip

Function encrypt_decrypt_roundtrip

nodedb-wal/src/crypto.rs:472–484  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

470
471 #[test]
472 fn encrypt_decrypt_roundtrip() {
473 let key = test_key();
474 let epoch = *key.epoch();
475 let header = test_header(1);
476 let plaintext = b"hello nodedb encryption";
477
478 let ciphertext = key.encrypt(1, &header, plaintext).unwrap();
479 assert_ne!(&ciphertext[..plaintext.len()], plaintext);
480 assert_eq!(ciphertext.len(), plaintext.len() + AUTH_TAG_SIZE);
481
482 let decrypted = key.decrypt(&epoch, 1, &header, &ciphertext).unwrap();
483 assert_eq!(decrypted, plaintext);
484 }
485
486 #[test]
487 fn wrong_key_fails() {

Callers

nothing calls this directly

Calls 5

test_headerFunction · 0.85
encryptMethod · 0.80
decryptMethod · 0.80
test_keyFunction · 0.70
epochMethod · 0.45

Tested by

no test coverage detected