pub struct AeaContext { /* private fields */ }Implementations§
Source§impl AeaContext
impl AeaContext
Sourcepub fn with_profile(profile: AeaProfile) -> Result<Self>
pub fn with_profile(profile: AeaProfile) -> Result<Self>
Examples found in repository?
examples/10_aea_roundtrip.rs (line 15)
10fn main() -> Result<(), Box<dyn std::error::Error>> {
11 let artifact_dir = artifact_dir("aea-roundtrip");
12 let archive_path = path_string(&artifact_dir.join("example.aea"));
13 let payload = pseudo_random_bytes(16 * 1024);
14
15 let mut context = AeaContext::with_profile(AeaProfile::HkdfSha256AesctrHmacSymmetricNone)?;
16 context.set_padding_size(AeaPadding::NONE)?;
17 context.set_compression_algorithm(ArchiveCompressionAlgorithm::Lzfse)?;
18 context.generate_field_blob(AeaContextField::SymmetricKey)?;
19
20 let stream = ByteStream::open_with_path(
21 &archive_path,
22 OPEN_READ_WRITE | OPEN_CREATE | OPEN_TRUNCATE,
23 DEFAULT_FILE_MODE,
24 )?;
25 let mut encrypted = context.encryption_output_stream(stream, ArchiveFlags::empty(), 0)?;
26 encrypted.write_all(&payload)?;
27 context.close_encryption_output_stream(&mut encrypted)?;
28
29 let symmetric_key =
30 context.field_blob(AeaContextField::SymmetricKey, AeaContextFieldRepresentation::Raw)?;
31 let mut input = ByteStream::open_with_path(&archive_path, OPEN_READ_ONLY, 0)?;
32 let mut decrypt_context = AeaContext::from_encrypted_stream(&mut input)?;
33 decrypt_context.set_symmetric_key(&symmetric_key)?;
34 let mut decrypted = decrypt_context.decryption_input_stream(input, ArchiveFlags::empty(), 0)?;
35 assert_eq!(decrypted.read_to_end()?, payload);
36
37 println!("raw_size={} container_size={}", context.raw_size()?, context.container_size()?);
38 println!("✅ AppleEncryptedArchive roundtrip OK");
39 Ok(())
40}Sourcepub fn from_encrypted_stream(stream: &mut ByteStream) -> Result<Self>
pub fn from_encrypted_stream(stream: &mut ByteStream) -> Result<Self>
Examples found in repository?
examples/10_aea_roundtrip.rs (line 32)
10fn main() -> Result<(), Box<dyn std::error::Error>> {
11 let artifact_dir = artifact_dir("aea-roundtrip");
12 let archive_path = path_string(&artifact_dir.join("example.aea"));
13 let payload = pseudo_random_bytes(16 * 1024);
14
15 let mut context = AeaContext::with_profile(AeaProfile::HkdfSha256AesctrHmacSymmetricNone)?;
16 context.set_padding_size(AeaPadding::NONE)?;
17 context.set_compression_algorithm(ArchiveCompressionAlgorithm::Lzfse)?;
18 context.generate_field_blob(AeaContextField::SymmetricKey)?;
19
20 let stream = ByteStream::open_with_path(
21 &archive_path,
22 OPEN_READ_WRITE | OPEN_CREATE | OPEN_TRUNCATE,
23 DEFAULT_FILE_MODE,
24 )?;
25 let mut encrypted = context.encryption_output_stream(stream, ArchiveFlags::empty(), 0)?;
26 encrypted.write_all(&payload)?;
27 context.close_encryption_output_stream(&mut encrypted)?;
28
29 let symmetric_key =
30 context.field_blob(AeaContextField::SymmetricKey, AeaContextFieldRepresentation::Raw)?;
31 let mut input = ByteStream::open_with_path(&archive_path, OPEN_READ_ONLY, 0)?;
32 let mut decrypt_context = AeaContext::from_encrypted_stream(&mut input)?;
33 decrypt_context.set_symmetric_key(&symmetric_key)?;
34 let mut decrypted = decrypt_context.decryption_input_stream(input, ArchiveFlags::empty(), 0)?;
35 assert_eq!(decrypted.read_to_end()?, payload);
36
37 println!("raw_size={} container_size={}", context.raw_size()?, context.container_size()?);
38 println!("✅ AppleEncryptedArchive roundtrip OK");
39 Ok(())
40}pub fn field_uint(&self, field: AeaContextField) -> Result<u64>
Sourcepub fn field_blob(
&self,
field: AeaContextField,
representation: AeaContextFieldRepresentation,
) -> Result<Vec<u8>>
pub fn field_blob( &self, field: AeaContextField, representation: AeaContextFieldRepresentation, ) -> Result<Vec<u8>>
Examples found in repository?
examples/10_aea_roundtrip.rs (line 30)
10fn main() -> Result<(), Box<dyn std::error::Error>> {
11 let artifact_dir = artifact_dir("aea-roundtrip");
12 let archive_path = path_string(&artifact_dir.join("example.aea"));
13 let payload = pseudo_random_bytes(16 * 1024);
14
15 let mut context = AeaContext::with_profile(AeaProfile::HkdfSha256AesctrHmacSymmetricNone)?;
16 context.set_padding_size(AeaPadding::NONE)?;
17 context.set_compression_algorithm(ArchiveCompressionAlgorithm::Lzfse)?;
18 context.generate_field_blob(AeaContextField::SymmetricKey)?;
19
20 let stream = ByteStream::open_with_path(
21 &archive_path,
22 OPEN_READ_WRITE | OPEN_CREATE | OPEN_TRUNCATE,
23 DEFAULT_FILE_MODE,
24 )?;
25 let mut encrypted = context.encryption_output_stream(stream, ArchiveFlags::empty(), 0)?;
26 encrypted.write_all(&payload)?;
27 context.close_encryption_output_stream(&mut encrypted)?;
28
29 let symmetric_key =
30 context.field_blob(AeaContextField::SymmetricKey, AeaContextFieldRepresentation::Raw)?;
31 let mut input = ByteStream::open_with_path(&archive_path, OPEN_READ_ONLY, 0)?;
32 let mut decrypt_context = AeaContext::from_encrypted_stream(&mut input)?;
33 decrypt_context.set_symmetric_key(&symmetric_key)?;
34 let mut decrypted = decrypt_context.decryption_input_stream(input, ArchiveFlags::empty(), 0)?;
35 assert_eq!(decrypted.read_to_end()?, payload);
36
37 println!("raw_size={} container_size={}", context.raw_size()?, context.container_size()?);
38 println!("✅ AppleEncryptedArchive roundtrip OK");
39 Ok(())
40}pub fn set_field_uint( &mut self, field: AeaContextField, value: u64, ) -> Result<()>
pub fn set_field_blob( &mut self, field: AeaContextField, representation: AeaContextFieldRepresentation, value: &[u8], ) -> Result<()>
Sourcepub fn generate_field_blob(&mut self, field: AeaContextField) -> Result<()>
pub fn generate_field_blob(&mut self, field: AeaContextField) -> Result<()>
Examples found in repository?
examples/10_aea_roundtrip.rs (line 18)
10fn main() -> Result<(), Box<dyn std::error::Error>> {
11 let artifact_dir = artifact_dir("aea-roundtrip");
12 let archive_path = path_string(&artifact_dir.join("example.aea"));
13 let payload = pseudo_random_bytes(16 * 1024);
14
15 let mut context = AeaContext::with_profile(AeaProfile::HkdfSha256AesctrHmacSymmetricNone)?;
16 context.set_padding_size(AeaPadding::NONE)?;
17 context.set_compression_algorithm(ArchiveCompressionAlgorithm::Lzfse)?;
18 context.generate_field_blob(AeaContextField::SymmetricKey)?;
19
20 let stream = ByteStream::open_with_path(
21 &archive_path,
22 OPEN_READ_WRITE | OPEN_CREATE | OPEN_TRUNCATE,
23 DEFAULT_FILE_MODE,
24 )?;
25 let mut encrypted = context.encryption_output_stream(stream, ArchiveFlags::empty(), 0)?;
26 encrypted.write_all(&payload)?;
27 context.close_encryption_output_stream(&mut encrypted)?;
28
29 let symmetric_key =
30 context.field_blob(AeaContextField::SymmetricKey, AeaContextFieldRepresentation::Raw)?;
31 let mut input = ByteStream::open_with_path(&archive_path, OPEN_READ_ONLY, 0)?;
32 let mut decrypt_context = AeaContext::from_encrypted_stream(&mut input)?;
33 decrypt_context.set_symmetric_key(&symmetric_key)?;
34 let mut decrypted = decrypt_context.decryption_input_stream(input, ArchiveFlags::empty(), 0)?;
35 assert_eq!(decrypted.read_to_end()?, payload);
36
37 println!("raw_size={} container_size={}", context.raw_size()?, context.container_size()?);
38 println!("✅ AppleEncryptedArchive roundtrip OK");
39 Ok(())
40}pub fn decrypt_attributes(&mut self) -> Result<()>
pub fn profile(&self) -> Result<AeaProfile>
pub fn checksum_mode(&self) -> Result<AeaChecksumMode>
pub fn compression_algorithm(&self) -> Result<ArchiveCompressionAlgorithm>
pub fn compression_block_size(&self) -> Result<usize>
Sourcepub fn raw_size(&self) -> Result<u64>
pub fn raw_size(&self) -> Result<u64>
Examples found in repository?
examples/10_aea_roundtrip.rs (line 37)
10fn main() -> Result<(), Box<dyn std::error::Error>> {
11 let artifact_dir = artifact_dir("aea-roundtrip");
12 let archive_path = path_string(&artifact_dir.join("example.aea"));
13 let payload = pseudo_random_bytes(16 * 1024);
14
15 let mut context = AeaContext::with_profile(AeaProfile::HkdfSha256AesctrHmacSymmetricNone)?;
16 context.set_padding_size(AeaPadding::NONE)?;
17 context.set_compression_algorithm(ArchiveCompressionAlgorithm::Lzfse)?;
18 context.generate_field_blob(AeaContextField::SymmetricKey)?;
19
20 let stream = ByteStream::open_with_path(
21 &archive_path,
22 OPEN_READ_WRITE | OPEN_CREATE | OPEN_TRUNCATE,
23 DEFAULT_FILE_MODE,
24 )?;
25 let mut encrypted = context.encryption_output_stream(stream, ArchiveFlags::empty(), 0)?;
26 encrypted.write_all(&payload)?;
27 context.close_encryption_output_stream(&mut encrypted)?;
28
29 let symmetric_key =
30 context.field_blob(AeaContextField::SymmetricKey, AeaContextFieldRepresentation::Raw)?;
31 let mut input = ByteStream::open_with_path(&archive_path, OPEN_READ_ONLY, 0)?;
32 let mut decrypt_context = AeaContext::from_encrypted_stream(&mut input)?;
33 decrypt_context.set_symmetric_key(&symmetric_key)?;
34 let mut decrypted = decrypt_context.decryption_input_stream(input, ArchiveFlags::empty(), 0)?;
35 assert_eq!(decrypted.read_to_end()?, payload);
36
37 println!("raw_size={} container_size={}", context.raw_size()?, context.container_size()?);
38 println!("✅ AppleEncryptedArchive roundtrip OK");
39 Ok(())
40}Sourcepub fn container_size(&self) -> Result<u64>
pub fn container_size(&self) -> Result<u64>
Examples found in repository?
examples/10_aea_roundtrip.rs (line 37)
10fn main() -> Result<(), Box<dyn std::error::Error>> {
11 let artifact_dir = artifact_dir("aea-roundtrip");
12 let archive_path = path_string(&artifact_dir.join("example.aea"));
13 let payload = pseudo_random_bytes(16 * 1024);
14
15 let mut context = AeaContext::with_profile(AeaProfile::HkdfSha256AesctrHmacSymmetricNone)?;
16 context.set_padding_size(AeaPadding::NONE)?;
17 context.set_compression_algorithm(ArchiveCompressionAlgorithm::Lzfse)?;
18 context.generate_field_blob(AeaContextField::SymmetricKey)?;
19
20 let stream = ByteStream::open_with_path(
21 &archive_path,
22 OPEN_READ_WRITE | OPEN_CREATE | OPEN_TRUNCATE,
23 DEFAULT_FILE_MODE,
24 )?;
25 let mut encrypted = context.encryption_output_stream(stream, ArchiveFlags::empty(), 0)?;
26 encrypted.write_all(&payload)?;
27 context.close_encryption_output_stream(&mut encrypted)?;
28
29 let symmetric_key =
30 context.field_blob(AeaContextField::SymmetricKey, AeaContextFieldRepresentation::Raw)?;
31 let mut input = ByteStream::open_with_path(&archive_path, OPEN_READ_ONLY, 0)?;
32 let mut decrypt_context = AeaContext::from_encrypted_stream(&mut input)?;
33 decrypt_context.set_symmetric_key(&symmetric_key)?;
34 let mut decrypted = decrypt_context.decryption_input_stream(input, ArchiveFlags::empty(), 0)?;
35 assert_eq!(decrypted.read_to_end()?, payload);
36
37 println!("raw_size={} container_size={}", context.raw_size()?, context.container_size()?);
38 println!("✅ AppleEncryptedArchive roundtrip OK");
39 Ok(())
40}pub fn auth_data(&self) -> Result<Vec<u8>>
pub fn signature_encryption_key(&self) -> Result<Vec<u8>>
pub fn archive_identifier(&self) -> Result<Vec<u8>>
pub fn main_key(&self) -> Result<Vec<u8>>
Sourcepub fn set_compression_algorithm(
&mut self,
compression_algorithm: ArchiveCompressionAlgorithm,
) -> Result<()>
pub fn set_compression_algorithm( &mut self, compression_algorithm: ArchiveCompressionAlgorithm, ) -> Result<()>
Examples found in repository?
examples/10_aea_roundtrip.rs (line 17)
10fn main() -> Result<(), Box<dyn std::error::Error>> {
11 let artifact_dir = artifact_dir("aea-roundtrip");
12 let archive_path = path_string(&artifact_dir.join("example.aea"));
13 let payload = pseudo_random_bytes(16 * 1024);
14
15 let mut context = AeaContext::with_profile(AeaProfile::HkdfSha256AesctrHmacSymmetricNone)?;
16 context.set_padding_size(AeaPadding::NONE)?;
17 context.set_compression_algorithm(ArchiveCompressionAlgorithm::Lzfse)?;
18 context.generate_field_blob(AeaContextField::SymmetricKey)?;
19
20 let stream = ByteStream::open_with_path(
21 &archive_path,
22 OPEN_READ_WRITE | OPEN_CREATE | OPEN_TRUNCATE,
23 DEFAULT_FILE_MODE,
24 )?;
25 let mut encrypted = context.encryption_output_stream(stream, ArchiveFlags::empty(), 0)?;
26 encrypted.write_all(&payload)?;
27 context.close_encryption_output_stream(&mut encrypted)?;
28
29 let symmetric_key =
30 context.field_blob(AeaContextField::SymmetricKey, AeaContextFieldRepresentation::Raw)?;
31 let mut input = ByteStream::open_with_path(&archive_path, OPEN_READ_ONLY, 0)?;
32 let mut decrypt_context = AeaContext::from_encrypted_stream(&mut input)?;
33 decrypt_context.set_symmetric_key(&symmetric_key)?;
34 let mut decrypted = decrypt_context.decryption_input_stream(input, ArchiveFlags::empty(), 0)?;
35 assert_eq!(decrypted.read_to_end()?, payload);
36
37 println!("raw_size={} container_size={}", context.raw_size()?, context.container_size()?);
38 println!("✅ AppleEncryptedArchive roundtrip OK");
39 Ok(())
40}pub fn set_compression_block_size( &mut self, compression_block_size: usize, ) -> Result<()>
pub fn set_checksum_mode( &mut self, checksum_mode: AeaChecksumMode, ) -> Result<()>
Sourcepub fn set_padding_size(&mut self, padding_size: u64) -> Result<()>
pub fn set_padding_size(&mut self, padding_size: u64) -> Result<()>
Examples found in repository?
examples/10_aea_roundtrip.rs (line 16)
10fn main() -> Result<(), Box<dyn std::error::Error>> {
11 let artifact_dir = artifact_dir("aea-roundtrip");
12 let archive_path = path_string(&artifact_dir.join("example.aea"));
13 let payload = pseudo_random_bytes(16 * 1024);
14
15 let mut context = AeaContext::with_profile(AeaProfile::HkdfSha256AesctrHmacSymmetricNone)?;
16 context.set_padding_size(AeaPadding::NONE)?;
17 context.set_compression_algorithm(ArchiveCompressionAlgorithm::Lzfse)?;
18 context.generate_field_blob(AeaContextField::SymmetricKey)?;
19
20 let stream = ByteStream::open_with_path(
21 &archive_path,
22 OPEN_READ_WRITE | OPEN_CREATE | OPEN_TRUNCATE,
23 DEFAULT_FILE_MODE,
24 )?;
25 let mut encrypted = context.encryption_output_stream(stream, ArchiveFlags::empty(), 0)?;
26 encrypted.write_all(&payload)?;
27 context.close_encryption_output_stream(&mut encrypted)?;
28
29 let symmetric_key =
30 context.field_blob(AeaContextField::SymmetricKey, AeaContextFieldRepresentation::Raw)?;
31 let mut input = ByteStream::open_with_path(&archive_path, OPEN_READ_ONLY, 0)?;
32 let mut decrypt_context = AeaContext::from_encrypted_stream(&mut input)?;
33 decrypt_context.set_symmetric_key(&symmetric_key)?;
34 let mut decrypted = decrypt_context.decryption_input_stream(input, ArchiveFlags::empty(), 0)?;
35 assert_eq!(decrypted.read_to_end()?, payload);
36
37 println!("raw_size={} container_size={}", context.raw_size()?, context.container_size()?);
38 println!("✅ AppleEncryptedArchive roundtrip OK");
39 Ok(())
40}pub fn set_auth_data_bytes(&mut self, auth_data: &[u8]) -> Result<()>
pub fn set_auth_data_blob(&mut self, auth_data: &AeaAuthData) -> Result<()>
pub fn set_signature_encryption_key(&mut self, key: &[u8]) -> Result<()>
Sourcepub fn set_symmetric_key(&mut self, key: &[u8]) -> Result<()>
pub fn set_symmetric_key(&mut self, key: &[u8]) -> Result<()>
Examples found in repository?
examples/10_aea_roundtrip.rs (line 33)
10fn main() -> Result<(), Box<dyn std::error::Error>> {
11 let artifact_dir = artifact_dir("aea-roundtrip");
12 let archive_path = path_string(&artifact_dir.join("example.aea"));
13 let payload = pseudo_random_bytes(16 * 1024);
14
15 let mut context = AeaContext::with_profile(AeaProfile::HkdfSha256AesctrHmacSymmetricNone)?;
16 context.set_padding_size(AeaPadding::NONE)?;
17 context.set_compression_algorithm(ArchiveCompressionAlgorithm::Lzfse)?;
18 context.generate_field_blob(AeaContextField::SymmetricKey)?;
19
20 let stream = ByteStream::open_with_path(
21 &archive_path,
22 OPEN_READ_WRITE | OPEN_CREATE | OPEN_TRUNCATE,
23 DEFAULT_FILE_MODE,
24 )?;
25 let mut encrypted = context.encryption_output_stream(stream, ArchiveFlags::empty(), 0)?;
26 encrypted.write_all(&payload)?;
27 context.close_encryption_output_stream(&mut encrypted)?;
28
29 let symmetric_key =
30 context.field_blob(AeaContextField::SymmetricKey, AeaContextFieldRepresentation::Raw)?;
31 let mut input = ByteStream::open_with_path(&archive_path, OPEN_READ_ONLY, 0)?;
32 let mut decrypt_context = AeaContext::from_encrypted_stream(&mut input)?;
33 decrypt_context.set_symmetric_key(&symmetric_key)?;
34 let mut decrypted = decrypt_context.decryption_input_stream(input, ArchiveFlags::empty(), 0)?;
35 assert_eq!(decrypted.read_to_end()?, payload);
36
37 println!("raw_size={} container_size={}", context.raw_size()?, context.container_size()?);
38 println!("✅ AppleEncryptedArchive roundtrip OK");
39 Ok(())
40}pub fn set_password(&mut self, password: &[u8]) -> Result<()>
pub fn set_signing_public_key(&mut self, key: &[u8]) -> Result<()>
pub fn set_signing_private_key(&mut self, key: &[u8]) -> Result<()>
pub fn set_recipient_public_key(&mut self, key: &[u8]) -> Result<()>
pub fn set_recipient_private_key(&mut self, key: &[u8]) -> Result<()>
pub fn set_main_key(&mut self, key: &[u8]) -> Result<()>
Sourcepub fn encryption_output_stream(
&self,
encrypted_stream: ByteStream,
flags: ArchiveFlags,
n_threads: i32,
) -> Result<ByteStream>
pub fn encryption_output_stream( &self, encrypted_stream: ByteStream, flags: ArchiveFlags, n_threads: i32, ) -> Result<ByteStream>
Examples found in repository?
examples/10_aea_roundtrip.rs (line 25)
10fn main() -> Result<(), Box<dyn std::error::Error>> {
11 let artifact_dir = artifact_dir("aea-roundtrip");
12 let archive_path = path_string(&artifact_dir.join("example.aea"));
13 let payload = pseudo_random_bytes(16 * 1024);
14
15 let mut context = AeaContext::with_profile(AeaProfile::HkdfSha256AesctrHmacSymmetricNone)?;
16 context.set_padding_size(AeaPadding::NONE)?;
17 context.set_compression_algorithm(ArchiveCompressionAlgorithm::Lzfse)?;
18 context.generate_field_blob(AeaContextField::SymmetricKey)?;
19
20 let stream = ByteStream::open_with_path(
21 &archive_path,
22 OPEN_READ_WRITE | OPEN_CREATE | OPEN_TRUNCATE,
23 DEFAULT_FILE_MODE,
24 )?;
25 let mut encrypted = context.encryption_output_stream(stream, ArchiveFlags::empty(), 0)?;
26 encrypted.write_all(&payload)?;
27 context.close_encryption_output_stream(&mut encrypted)?;
28
29 let symmetric_key =
30 context.field_blob(AeaContextField::SymmetricKey, AeaContextFieldRepresentation::Raw)?;
31 let mut input = ByteStream::open_with_path(&archive_path, OPEN_READ_ONLY, 0)?;
32 let mut decrypt_context = AeaContext::from_encrypted_stream(&mut input)?;
33 decrypt_context.set_symmetric_key(&symmetric_key)?;
34 let mut decrypted = decrypt_context.decryption_input_stream(input, ArchiveFlags::empty(), 0)?;
35 assert_eq!(decrypted.read_to_end()?, payload);
36
37 println!("raw_size={} container_size={}", context.raw_size()?, context.container_size()?);
38 println!("✅ AppleEncryptedArchive roundtrip OK");
39 Ok(())
40}pub fn encryption_output_stream_existing( &self, encrypted_stream: ByteStream, flags: ArchiveFlags, n_threads: i32, ) -> Result<ByteStream>
Sourcepub fn decryption_input_stream(
&mut self,
encrypted_stream: ByteStream,
flags: ArchiveFlags,
n_threads: i32,
) -> Result<ByteStream>
pub fn decryption_input_stream( &mut self, encrypted_stream: ByteStream, flags: ArchiveFlags, n_threads: i32, ) -> Result<ByteStream>
Examples found in repository?
examples/10_aea_roundtrip.rs (line 34)
10fn main() -> Result<(), Box<dyn std::error::Error>> {
11 let artifact_dir = artifact_dir("aea-roundtrip");
12 let archive_path = path_string(&artifact_dir.join("example.aea"));
13 let payload = pseudo_random_bytes(16 * 1024);
14
15 let mut context = AeaContext::with_profile(AeaProfile::HkdfSha256AesctrHmacSymmetricNone)?;
16 context.set_padding_size(AeaPadding::NONE)?;
17 context.set_compression_algorithm(ArchiveCompressionAlgorithm::Lzfse)?;
18 context.generate_field_blob(AeaContextField::SymmetricKey)?;
19
20 let stream = ByteStream::open_with_path(
21 &archive_path,
22 OPEN_READ_WRITE | OPEN_CREATE | OPEN_TRUNCATE,
23 DEFAULT_FILE_MODE,
24 )?;
25 let mut encrypted = context.encryption_output_stream(stream, ArchiveFlags::empty(), 0)?;
26 encrypted.write_all(&payload)?;
27 context.close_encryption_output_stream(&mut encrypted)?;
28
29 let symmetric_key =
30 context.field_blob(AeaContextField::SymmetricKey, AeaContextFieldRepresentation::Raw)?;
31 let mut input = ByteStream::open_with_path(&archive_path, OPEN_READ_ONLY, 0)?;
32 let mut decrypt_context = AeaContext::from_encrypted_stream(&mut input)?;
33 decrypt_context.set_symmetric_key(&symmetric_key)?;
34 let mut decrypted = decrypt_context.decryption_input_stream(input, ArchiveFlags::empty(), 0)?;
35 assert_eq!(decrypted.read_to_end()?, payload);
36
37 println!("raw_size={} container_size={}", context.raw_size()?, context.container_size()?);
38 println!("✅ AppleEncryptedArchive roundtrip OK");
39 Ok(())
40}pub fn decryption_random_access_input_stream( &mut self, encrypted_stream: ByteStream, alloc_limit: usize, flags: ArchiveFlags, n_threads: i32, ) -> Result<ByteStream>
Sourcepub fn close_encryption_output_stream(
&mut self,
stream: &mut ByteStream,
) -> Result<()>
pub fn close_encryption_output_stream( &mut self, stream: &mut ByteStream, ) -> Result<()>
Examples found in repository?
examples/10_aea_roundtrip.rs (line 27)
10fn main() -> Result<(), Box<dyn std::error::Error>> {
11 let artifact_dir = artifact_dir("aea-roundtrip");
12 let archive_path = path_string(&artifact_dir.join("example.aea"));
13 let payload = pseudo_random_bytes(16 * 1024);
14
15 let mut context = AeaContext::with_profile(AeaProfile::HkdfSha256AesctrHmacSymmetricNone)?;
16 context.set_padding_size(AeaPadding::NONE)?;
17 context.set_compression_algorithm(ArchiveCompressionAlgorithm::Lzfse)?;
18 context.generate_field_blob(AeaContextField::SymmetricKey)?;
19
20 let stream = ByteStream::open_with_path(
21 &archive_path,
22 OPEN_READ_WRITE | OPEN_CREATE | OPEN_TRUNCATE,
23 DEFAULT_FILE_MODE,
24 )?;
25 let mut encrypted = context.encryption_output_stream(stream, ArchiveFlags::empty(), 0)?;
26 encrypted.write_all(&payload)?;
27 context.close_encryption_output_stream(&mut encrypted)?;
28
29 let symmetric_key =
30 context.field_blob(AeaContextField::SymmetricKey, AeaContextFieldRepresentation::Raw)?;
31 let mut input = ByteStream::open_with_path(&archive_path, OPEN_READ_ONLY, 0)?;
32 let mut decrypt_context = AeaContext::from_encrypted_stream(&mut input)?;
33 decrypt_context.set_symmetric_key(&symmetric_key)?;
34 let mut decrypted = decrypt_context.decryption_input_stream(input, ArchiveFlags::empty(), 0)?;
35 assert_eq!(decrypted.read_to_end()?, payload);
36
37 println!("raw_size={} container_size={}", context.raw_size()?, context.container_size()?);
38 println!("✅ AppleEncryptedArchive roundtrip OK");
39 Ok(())
40}pub fn sign_stream(&self, stream: &mut ByteStream) -> Result<()>
Trait Implementations§
Source§impl Debug for AeaContext
impl Debug for AeaContext
Source§impl Drop for AeaContext
impl Drop for AeaContext
Auto Trait Implementations§
impl Freeze for AeaContext
impl RefUnwindSafe for AeaContext
impl !Send for AeaContext
impl !Sync for AeaContext
impl Unpin for AeaContext
impl UnsafeUnpin for AeaContext
impl UnwindSafe for AeaContext
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more