|
1 | 1 | use alloc::boxed::Box;
|
2 | 2 | use alloc::string::String;
|
| 3 | +use alloc::vec::Vec; |
3 | 4 | use core::fmt;
|
4 | 5 |
|
5 | 6 | use chacha20poly1305::aead::{Aead, AeadCore, KeyInit};
|
6 | 7 | use chacha20poly1305::{ChaCha20Poly1305, Key, Nonce};
|
7 | 8 | use ferveo::api::{CiphertextHeader, FerveoVariant};
|
8 | 9 | use generic_array::typenum::Unsigned;
|
9 | 10 | use rand_core::{CryptoRng, RngCore};
|
10 |
| -use serde::{Deserialize, Serialize}; |
| 11 | +use serde::{Deserialize, Deserializer, Serialize, Serializer}; |
| 12 | +use serde_json; |
11 | 13 | use umbral_pre::serde_bytes; // TODO should this be in umbral?
|
12 | 14 |
|
13 | 15 | use crate::access_control::AccessControlPolicy;
|
14 | 16 | use crate::conditions::Context;
|
15 |
| -use crate::dkg::session::{SessionSharedSecret, SessionStaticKey}; |
| 17 | +use crate::dkg::session::{SessionSharedSecret, SessionStaticKey, SessionSecretFactory}; |
16 | 18 | use crate::versioning::{
|
17 | 19 | messagepack_deserialize, messagepack_serialize, DeserializationError, ProtocolObject,
|
18 | 20 | ProtocolObjectInner,
|
@@ -617,26 +619,41 @@ impl ProtocolObject<'_> for EncryptedThresholdDecryptionResponse {}
|
617 | 619 |
|
618 | 620 | #[cfg(test)]
|
619 | 621 | mod tests {
|
| 622 | + use crate::dkg::session::{SessionSharedSecret, SessionStaticSecret, SessionSecretFactory, SessionStaticKey}; |
| 623 | + use crate::dkg::{ |
| 624 | + decrypt_with_shared_secret, encrypt_with_shared_secret, DecryptionError, NonceSize, |
| 625 | + ThresholdDecryptionRequest, EncryptedThresholdDecryptionRequest, |
| 626 | + ThresholdDecryptionResponse, EncryptedThresholdDecryptionResponse, |
| 627 | + }; |
| 628 | + use crate::{AuthenticatedData, Conditions}; |
620 | 629 | use alloc::vec;
|
621 | 630 | use alloc::vec::Vec;
|
622 | 631 | use alloc::boxed::Box;
|
623 |
| - use ferveo::api::{encrypt as ferveo_encrypt, DkgPublicKey, FerveoVariant, SecretBox}; |
| 632 | + use core::clone::Clone; |
| 633 | + use ferveo::api::{DkgPublicKey, FerveoVariant, SecretBox, encrypt as ferveo_encrypt}; |
624 | 634 | use generic_array::typenum::Unsigned;
|
| 635 | + use rand::SeedableRng; |
| 636 | + use rand::rngs::StdRng; |
625 | 637 | use rand_core::RngCore;
|
| 638 | + use serde::{Deserialize, Serialize}; |
| 639 | + use serde_json; |
| 640 | + use x25519_dalek::{PublicKey, StaticSecret}; |
626 | 641 |
|
627 | 642 | use crate::access_control::AccessControlPolicy;
|
628 |
| - use crate::conditions::{Conditions, Context}; |
629 |
| - use crate::dkg::session::{SessionSharedSecret, SessionStaticSecret}; |
630 |
| - use crate::dkg::{ |
631 |
| - decrypt_with_shared_secret, encrypt_with_shared_secret, DecryptionError, NonceSize, |
632 |
| - }; |
633 |
| - use crate::versioning::{ProtocolObject, ProtocolObjectInner}; |
634 |
| - use crate::{ |
635 |
| - AuthenticatedData, EncryptedThresholdDecryptionRequest, |
636 |
| - EncryptedThresholdDecryptionResponse, SessionSecretFactory, SessionStaticKey, |
637 |
| - ThresholdDecryptionRequest, ThresholdDecryptionResponse, |
| 643 | + use crate::conditions::Context; |
| 644 | + use crate::versioning::{ |
| 645 | + messagepack_deserialize, messagepack_serialize, DeserializationError, ProtocolObject, |
| 646 | + ProtocolObjectInner, |
638 | 647 | };
|
639 | 648 |
|
| 649 | + #[cfg(feature = "deterministic_encryption")] |
| 650 | + #[derive(Serialize, Deserialize)] |
| 651 | + pub struct TestVector { |
| 652 | + pub seed: u8, |
| 653 | + pub plaintext: Vec<u8>, |
| 654 | + pub ciphertext: Box<[u8]>, |
| 655 | + } |
| 656 | + |
640 | 657 | #[test]
|
641 | 658 | fn decryption_with_shared_secret() {
|
642 | 659 | let service_secret = SessionStaticSecret::random();
|
@@ -860,13 +877,6 @@ mod tests {
|
860 | 877 | .is_err());
|
861 | 878 | }
|
862 | 879 |
|
863 |
| - #[cfg(feature = "deterministic_encryption")] |
864 |
| - pub struct TestVector { |
865 |
| - pub seed: u8, |
866 |
| - pub plaintext: Vec<u8>, |
867 |
| - pub ciphertext: Box<[u8]>, |
868 |
| - } |
869 |
| - |
870 | 880 | #[cfg(feature = "deterministic_encryption")]
|
871 | 881 | pub fn generate_test_vectors() -> Vec<TestVector> {
|
872 | 882 | let mut test_vectors = Vec::new();
|
|
0 commit comments