pub struct AeaContext { /* private fields */ }Expand description
Wraps an AEAContext handle.
Implementations§
Source§impl AeaContext
impl AeaContext
Sourcepub fn with_profile(profile: AeaProfile) -> Result<Self>
pub fn with_profile(profile: AeaProfile) -> Result<Self>
Wraps AEAContextCreateWithProfile.
Examples found in repository?
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 = context.field_blob(
30 AeaContextField::SymmetricKey,
31 AeaContextFieldRepresentation::Raw,
32 )?;
33 let mut input = ByteStream::open_with_path(&archive_path, OPEN_READ_ONLY, 0)?;
34 let mut decrypt_context = AeaContext::from_encrypted_stream(&mut input)?;
35 decrypt_context.set_symmetric_key(&symmetric_key)?;
36 let mut decrypted = decrypt_context.decryption_input_stream(input, ArchiveFlags::empty(), 0)?;
37 assert_eq!(decrypted.read_to_end()?, payload);
38
39 println!(
40 "raw_size={} container_size={}",
41 context.raw_size()?,
42 context.container_size()?
43 );
44 println!("✅ AppleEncryptedArchive roundtrip OK");
45 Ok(())
46}Sourcepub fn from_encrypted_stream(stream: &mut ByteStream) -> Result<Self>
pub fn from_encrypted_stream(stream: &mut ByteStream) -> Result<Self>
Wraps AEAContextCreateWithEncryptedStream.
Examples found in repository?
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 = context.field_blob(
30 AeaContextField::SymmetricKey,
31 AeaContextFieldRepresentation::Raw,
32 )?;
33 let mut input = ByteStream::open_with_path(&archive_path, OPEN_READ_ONLY, 0)?;
34 let mut decrypt_context = AeaContext::from_encrypted_stream(&mut input)?;
35 decrypt_context.set_symmetric_key(&symmetric_key)?;
36 let mut decrypted = decrypt_context.decryption_input_stream(input, ArchiveFlags::empty(), 0)?;
37 assert_eq!(decrypted.read_to_end()?, payload);
38
39 println!(
40 "raw_size={} container_size={}",
41 context.raw_size()?,
42 context.container_size()?
43 );
44 println!("✅ AppleEncryptedArchive roundtrip OK");
45 Ok(())
46}Sourcepub fn field_uint(&self, field: AeaContextField) -> Result<u64>
pub fn field_uint(&self, field: AeaContextField) -> Result<u64>
Wraps AEAContextGetFieldUInt.
Sourcepub fn field_blob(
&self,
field: AeaContextField,
representation: AeaContextFieldRepresentation,
) -> Result<Vec<u8>>
pub fn field_blob( &self, field: AeaContextField, representation: AeaContextFieldRepresentation, ) -> Result<Vec<u8>>
Wraps AEAContextGetFieldBlob.
Examples found in repository?
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 = context.field_blob(
30 AeaContextField::SymmetricKey,
31 AeaContextFieldRepresentation::Raw,
32 )?;
33 let mut input = ByteStream::open_with_path(&archive_path, OPEN_READ_ONLY, 0)?;
34 let mut decrypt_context = AeaContext::from_encrypted_stream(&mut input)?;
35 decrypt_context.set_symmetric_key(&symmetric_key)?;
36 let mut decrypted = decrypt_context.decryption_input_stream(input, ArchiveFlags::empty(), 0)?;
37 assert_eq!(decrypted.read_to_end()?, payload);
38
39 println!(
40 "raw_size={} container_size={}",
41 context.raw_size()?,
42 context.container_size()?
43 );
44 println!("✅ AppleEncryptedArchive roundtrip OK");
45 Ok(())
46}Sourcepub fn set_field_uint(
&mut self,
field: AeaContextField,
value: u64,
) -> Result<()>
pub fn set_field_uint( &mut self, field: AeaContextField, value: u64, ) -> Result<()>
Wraps AEAContextSetFieldUInt.
Sourcepub fn set_field_blob(
&mut self,
field: AeaContextField,
representation: AeaContextFieldRepresentation,
value: &[u8],
) -> Result<()>
pub fn set_field_blob( &mut self, field: AeaContextField, representation: AeaContextFieldRepresentation, value: &[u8], ) -> Result<()>
Wraps AEAContextSetFieldBlob.
Sourcepub fn generate_field_blob(&mut self, field: AeaContextField) -> Result<()>
pub fn generate_field_blob(&mut self, field: AeaContextField) -> Result<()>
Wraps AEAContextGenerateFieldBlob.
Examples found in repository?
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 = context.field_blob(
30 AeaContextField::SymmetricKey,
31 AeaContextFieldRepresentation::Raw,
32 )?;
33 let mut input = ByteStream::open_with_path(&archive_path, OPEN_READ_ONLY, 0)?;
34 let mut decrypt_context = AeaContext::from_encrypted_stream(&mut input)?;
35 decrypt_context.set_symmetric_key(&symmetric_key)?;
36 let mut decrypted = decrypt_context.decryption_input_stream(input, ArchiveFlags::empty(), 0)?;
37 assert_eq!(decrypted.read_to_end()?, payload);
38
39 println!(
40 "raw_size={} container_size={}",
41 context.raw_size()?,
42 context.container_size()?
43 );
44 println!("✅ AppleEncryptedArchive roundtrip OK");
45 Ok(())
46}Sourcepub fn decrypt_attributes(&mut self) -> Result<()>
pub fn decrypt_attributes(&mut self) -> Result<()>
Wraps AEAContextDecryptAttributes.
Sourcepub fn profile(&self) -> Result<AeaProfile>
pub fn profile(&self) -> Result<AeaProfile>
Wraps AEAContextGetProfile.
Sourcepub fn checksum_mode(&self) -> Result<AeaChecksumMode>
pub fn checksum_mode(&self) -> Result<AeaChecksumMode>
Wraps AEAContextGetChecksumMode.
Sourcepub fn compression_algorithm(&self) -> Result<ArchiveCompressionAlgorithm>
pub fn compression_algorithm(&self) -> Result<ArchiveCompressionAlgorithm>
Wraps AEAContextGetCompressionAlgorithm.
Sourcepub fn compression_block_size(&self) -> Result<usize>
pub fn compression_block_size(&self) -> Result<usize>
Wraps AEAContextGetCompressionBlockSize.
Sourcepub fn raw_size(&self) -> Result<u64>
pub fn raw_size(&self) -> Result<u64>
Wraps AEAContextGetFieldUInt for RawSize.
Examples found in repository?
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 = context.field_blob(
30 AeaContextField::SymmetricKey,
31 AeaContextFieldRepresentation::Raw,
32 )?;
33 let mut input = ByteStream::open_with_path(&archive_path, OPEN_READ_ONLY, 0)?;
34 let mut decrypt_context = AeaContext::from_encrypted_stream(&mut input)?;
35 decrypt_context.set_symmetric_key(&symmetric_key)?;
36 let mut decrypted = decrypt_context.decryption_input_stream(input, ArchiveFlags::empty(), 0)?;
37 assert_eq!(decrypted.read_to_end()?, payload);
38
39 println!(
40 "raw_size={} container_size={}",
41 context.raw_size()?,
42 context.container_size()?
43 );
44 println!("✅ AppleEncryptedArchive roundtrip OK");
45 Ok(())
46}Sourcepub fn container_size(&self) -> Result<u64>
pub fn container_size(&self) -> Result<u64>
Wraps AEAContextGetFieldUInt for ContainerSize.
Examples found in repository?
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 = context.field_blob(
30 AeaContextField::SymmetricKey,
31 AeaContextFieldRepresentation::Raw,
32 )?;
33 let mut input = ByteStream::open_with_path(&archive_path, OPEN_READ_ONLY, 0)?;
34 let mut decrypt_context = AeaContext::from_encrypted_stream(&mut input)?;
35 decrypt_context.set_symmetric_key(&symmetric_key)?;
36 let mut decrypted = decrypt_context.decryption_input_stream(input, ArchiveFlags::empty(), 0)?;
37 assert_eq!(decrypted.read_to_end()?, payload);
38
39 println!(
40 "raw_size={} container_size={}",
41 context.raw_size()?,
42 context.container_size()?
43 );
44 println!("✅ AppleEncryptedArchive roundtrip OK");
45 Ok(())
46}Sourcepub fn signature_encryption_key(&self) -> Result<Vec<u8>>
pub fn signature_encryption_key(&self) -> Result<Vec<u8>>
Wraps the signature_encryption_key convenience for AeaContext.
Sourcepub fn archive_identifier(&self) -> Result<Vec<u8>>
pub fn archive_identifier(&self) -> Result<Vec<u8>>
Wraps the archive_identifier convenience for AeaContext.
Sourcepub fn set_compression_algorithm(
&mut self,
compression_algorithm: ArchiveCompressionAlgorithm,
) -> Result<()>
pub fn set_compression_algorithm( &mut self, compression_algorithm: ArchiveCompressionAlgorithm, ) -> Result<()>
Wraps the set_compression_algorithm convenience for AeaContext.
Examples found in repository?
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 = context.field_blob(
30 AeaContextField::SymmetricKey,
31 AeaContextFieldRepresentation::Raw,
32 )?;
33 let mut input = ByteStream::open_with_path(&archive_path, OPEN_READ_ONLY, 0)?;
34 let mut decrypt_context = AeaContext::from_encrypted_stream(&mut input)?;
35 decrypt_context.set_symmetric_key(&symmetric_key)?;
36 let mut decrypted = decrypt_context.decryption_input_stream(input, ArchiveFlags::empty(), 0)?;
37 assert_eq!(decrypted.read_to_end()?, payload);
38
39 println!(
40 "raw_size={} container_size={}",
41 context.raw_size()?,
42 context.container_size()?
43 );
44 println!("✅ AppleEncryptedArchive roundtrip OK");
45 Ok(())
46}Sourcepub fn set_compression_block_size(
&mut self,
compression_block_size: usize,
) -> Result<()>
pub fn set_compression_block_size( &mut self, compression_block_size: usize, ) -> Result<()>
Wraps the set_compression_block_size convenience for AeaContext.
Sourcepub fn set_checksum_mode(
&mut self,
checksum_mode: AeaChecksumMode,
) -> Result<()>
pub fn set_checksum_mode( &mut self, checksum_mode: AeaChecksumMode, ) -> Result<()>
Wraps the set_checksum_mode convenience for AeaContext.
Sourcepub fn set_padding_size(&mut self, padding_size: u64) -> Result<()>
pub fn set_padding_size(&mut self, padding_size: u64) -> Result<()>
Wraps the set_padding_size convenience for AeaContext.
Examples found in repository?
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 = context.field_blob(
30 AeaContextField::SymmetricKey,
31 AeaContextFieldRepresentation::Raw,
32 )?;
33 let mut input = ByteStream::open_with_path(&archive_path, OPEN_READ_ONLY, 0)?;
34 let mut decrypt_context = AeaContext::from_encrypted_stream(&mut input)?;
35 decrypt_context.set_symmetric_key(&symmetric_key)?;
36 let mut decrypted = decrypt_context.decryption_input_stream(input, ArchiveFlags::empty(), 0)?;
37 assert_eq!(decrypted.read_to_end()?, payload);
38
39 println!(
40 "raw_size={} container_size={}",
41 context.raw_size()?,
42 context.container_size()?
43 );
44 println!("✅ AppleEncryptedArchive roundtrip OK");
45 Ok(())
46}Sourcepub fn set_auth_data_bytes(&mut self, auth_data: &[u8]) -> Result<()>
pub fn set_auth_data_bytes(&mut self, auth_data: &[u8]) -> Result<()>
Wraps the set_auth_data_bytes convenience for AeaContext.
Sourcepub fn set_auth_data_blob(&mut self, auth_data: &AeaAuthData) -> Result<()>
pub fn set_auth_data_blob(&mut self, auth_data: &AeaAuthData) -> Result<()>
Wraps the set_auth_data_blob convenience for AeaContext.
Sourcepub fn set_signature_encryption_key(&mut self, key: &[u8]) -> Result<()>
pub fn set_signature_encryption_key(&mut self, key: &[u8]) -> Result<()>
Wraps the set_signature_encryption_key convenience for AeaContext.
Sourcepub fn set_symmetric_key(&mut self, key: &[u8]) -> Result<()>
pub fn set_symmetric_key(&mut self, key: &[u8]) -> Result<()>
Wraps the set_symmetric_key convenience for AeaContext.
Examples found in repository?
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 = context.field_blob(
30 AeaContextField::SymmetricKey,
31 AeaContextFieldRepresentation::Raw,
32 )?;
33 let mut input = ByteStream::open_with_path(&archive_path, OPEN_READ_ONLY, 0)?;
34 let mut decrypt_context = AeaContext::from_encrypted_stream(&mut input)?;
35 decrypt_context.set_symmetric_key(&symmetric_key)?;
36 let mut decrypted = decrypt_context.decryption_input_stream(input, ArchiveFlags::empty(), 0)?;
37 assert_eq!(decrypted.read_to_end()?, payload);
38
39 println!(
40 "raw_size={} container_size={}",
41 context.raw_size()?,
42 context.container_size()?
43 );
44 println!("✅ AppleEncryptedArchive roundtrip OK");
45 Ok(())
46}Sourcepub fn set_password(&mut self, password: &[u8]) -> Result<()>
pub fn set_password(&mut self, password: &[u8]) -> Result<()>
Wraps the set_password convenience for AeaContext.
Sourcepub fn set_signing_public_key(&mut self, key: &[u8]) -> Result<()>
pub fn set_signing_public_key(&mut self, key: &[u8]) -> Result<()>
Wraps the set_signing_public_key convenience for AeaContext.
Sourcepub fn set_signing_private_key(&mut self, key: &[u8]) -> Result<()>
pub fn set_signing_private_key(&mut self, key: &[u8]) -> Result<()>
Wraps AEAEncryptionOutputStreamOpen.
Sourcepub fn set_recipient_public_key(&mut self, key: &[u8]) -> Result<()>
pub fn set_recipient_public_key(&mut self, key: &[u8]) -> Result<()>
Wraps AEAEncryptionOutputStreamOpen.
Sourcepub fn set_recipient_private_key(&mut self, key: &[u8]) -> Result<()>
pub fn set_recipient_private_key(&mut self, key: &[u8]) -> Result<()>
Wraps AEAEncryptionOutputStreamOpen.
Sourcepub fn set_main_key(&mut self, key: &[u8]) -> Result<()>
pub fn set_main_key(&mut self, key: &[u8]) -> Result<()>
Wraps AEAEncryptionOutputStreamOpen.
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>
Wraps AEAEncryptionOutputStreamOpen.
Examples found in repository?
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 = context.field_blob(
30 AeaContextField::SymmetricKey,
31 AeaContextFieldRepresentation::Raw,
32 )?;
33 let mut input = ByteStream::open_with_path(&archive_path, OPEN_READ_ONLY, 0)?;
34 let mut decrypt_context = AeaContext::from_encrypted_stream(&mut input)?;
35 decrypt_context.set_symmetric_key(&symmetric_key)?;
36 let mut decrypted = decrypt_context.decryption_input_stream(input, ArchiveFlags::empty(), 0)?;
37 assert_eq!(decrypted.read_to_end()?, payload);
38
39 println!(
40 "raw_size={} container_size={}",
41 context.raw_size()?,
42 context.container_size()?
43 );
44 println!("✅ AppleEncryptedArchive roundtrip OK");
45 Ok(())
46}Sourcepub fn encryption_output_stream_existing(
&self,
encrypted_stream: ByteStream,
flags: ArchiveFlags,
n_threads: i32,
) -> Result<ByteStream>
pub fn encryption_output_stream_existing( &self, encrypted_stream: ByteStream, flags: ArchiveFlags, n_threads: i32, ) -> Result<ByteStream>
Wraps AEAEncryptionOutputStreamOpenExisting.
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>
Wraps AEADecryptionInputStreamOpen.
Examples found in repository?
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 = context.field_blob(
30 AeaContextField::SymmetricKey,
31 AeaContextFieldRepresentation::Raw,
32 )?;
33 let mut input = ByteStream::open_with_path(&archive_path, OPEN_READ_ONLY, 0)?;
34 let mut decrypt_context = AeaContext::from_encrypted_stream(&mut input)?;
35 decrypt_context.set_symmetric_key(&symmetric_key)?;
36 let mut decrypted = decrypt_context.decryption_input_stream(input, ArchiveFlags::empty(), 0)?;
37 assert_eq!(decrypted.read_to_end()?, payload);
38
39 println!(
40 "raw_size={} container_size={}",
41 context.raw_size()?,
42 context.container_size()?
43 );
44 println!("✅ AppleEncryptedArchive roundtrip OK");
45 Ok(())
46}Sourcepub fn decryption_random_access_input_stream(
&mut self,
encrypted_stream: ByteStream,
alloc_limit: usize,
flags: ArchiveFlags,
n_threads: i32,
) -> Result<ByteStream>
pub fn decryption_random_access_input_stream( &mut self, encrypted_stream: ByteStream, alloc_limit: usize, flags: ArchiveFlags, n_threads: i32, ) -> Result<ByteStream>
Wraps AEADecryptionRandomAccessInputStreamOpen.
Sourcepub fn close_encryption_output_stream(
&mut self,
stream: &mut ByteStream,
) -> Result<()>
pub fn close_encryption_output_stream( &mut self, stream: &mut ByteStream, ) -> Result<()>
Wraps AEAEncryptionOutputStreamCloseAndUpdateContext.
Examples found in repository?
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 = context.field_blob(
30 AeaContextField::SymmetricKey,
31 AeaContextFieldRepresentation::Raw,
32 )?;
33 let mut input = ByteStream::open_with_path(&archive_path, OPEN_READ_ONLY, 0)?;
34 let mut decrypt_context = AeaContext::from_encrypted_stream(&mut input)?;
35 decrypt_context.set_symmetric_key(&symmetric_key)?;
36 let mut decrypted = decrypt_context.decryption_input_stream(input, ArchiveFlags::empty(), 0)?;
37 assert_eq!(decrypted.read_to_end()?, payload);
38
39 println!(
40 "raw_size={} container_size={}",
41 context.raw_size()?,
42 context.container_size()?
43 );
44 println!("✅ AppleEncryptedArchive roundtrip OK");
45 Ok(())
46}Sourcepub fn sign_stream(&self, stream: &mut ByteStream) -> Result<()>
pub fn sign_stream(&self, stream: &mut ByteStream) -> Result<()>
Wraps AEAStreamSign.