Skip to main content

AeaContext

Struct AeaContext 

Source
pub struct AeaContext { /* private fields */ }
Expand description

Wraps an AEAContext handle.

Implementations§

Source§

impl AeaContext

Source

pub fn with_profile(profile: AeaProfile) -> Result<Self>

Wraps AEAContextCreateWithProfile.

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 = 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}
Source

pub fn from_encrypted_stream(stream: &mut ByteStream) -> Result<Self>

Wraps AEAContextCreateWithEncryptedStream.

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 = 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}
Source

pub fn field_uint(&self, field: AeaContextField) -> Result<u64>

Wraps AEAContextGetFieldUInt.

Source

pub fn field_blob( &self, field: AeaContextField, representation: AeaContextFieldRepresentation, ) -> Result<Vec<u8>>

Wraps AEAContextGetFieldBlob.

Examples found in repository?
examples/10_aea_roundtrip.rs (lines 29-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 = 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}
Source

pub fn set_field_uint( &mut self, field: AeaContextField, value: u64, ) -> Result<()>

Wraps AEAContextSetFieldUInt.

Source

pub fn set_field_blob( &mut self, field: AeaContextField, representation: AeaContextFieldRepresentation, value: &[u8], ) -> Result<()>

Wraps AEAContextSetFieldBlob.

Source

pub fn generate_field_blob(&mut self, field: AeaContextField) -> Result<()>

Wraps AEAContextGenerateFieldBlob.

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 = 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}
Source

pub fn decrypt_attributes(&mut self) -> Result<()>

Wraps AEAContextDecryptAttributes.

Source

pub fn profile(&self) -> Result<AeaProfile>

Wraps AEAContextGetProfile.

Source

pub fn checksum_mode(&self) -> Result<AeaChecksumMode>

Wraps AEAContextGetChecksumMode.

Source

pub fn compression_algorithm(&self) -> Result<ArchiveCompressionAlgorithm>

Wraps AEAContextGetCompressionAlgorithm.

Source

pub fn compression_block_size(&self) -> Result<usize>

Wraps AEAContextGetCompressionBlockSize.

Source

pub fn raw_size(&self) -> Result<u64>

Wraps AEAContextGetFieldUInt for RawSize.

Examples found in repository?
examples/10_aea_roundtrip.rs (line 41)
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}
Source

pub fn container_size(&self) -> Result<u64>

Wraps AEAContextGetFieldUInt for ContainerSize.

Examples found in repository?
examples/10_aea_roundtrip.rs (line 42)
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}
Source

pub fn auth_data(&self) -> Result<Vec<u8>>

Wraps the auth_data convenience for AeaContext.

Source

pub fn signature_encryption_key(&self) -> Result<Vec<u8>>

Wraps the signature_encryption_key convenience for AeaContext.

Source

pub fn archive_identifier(&self) -> Result<Vec<u8>>

Wraps the archive_identifier convenience for AeaContext.

Source

pub fn main_key(&self) -> Result<Vec<u8>>

Wraps the main_key convenience for AeaContext.

Source

pub fn set_compression_algorithm( &mut self, compression_algorithm: ArchiveCompressionAlgorithm, ) -> Result<()>

Wraps the set_compression_algorithm convenience for AeaContext.

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 = 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}
Source

pub fn set_compression_block_size( &mut self, compression_block_size: usize, ) -> Result<()>

Wraps the set_compression_block_size convenience for AeaContext.

Source

pub fn set_checksum_mode( &mut self, checksum_mode: AeaChecksumMode, ) -> Result<()>

Wraps the set_checksum_mode convenience for AeaContext.

Source

pub fn set_padding_size(&mut self, padding_size: u64) -> Result<()>

Wraps the set_padding_size convenience for AeaContext.

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 = 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}
Source

pub fn set_auth_data_bytes(&mut self, auth_data: &[u8]) -> Result<()>

Wraps the set_auth_data_bytes convenience for AeaContext.

Source

pub fn set_auth_data_blob(&mut self, auth_data: &AeaAuthData) -> Result<()>

Wraps the set_auth_data_blob convenience for AeaContext.

Source

pub fn set_signature_encryption_key(&mut self, key: &[u8]) -> Result<()>

Wraps the set_signature_encryption_key convenience for AeaContext.

Source

pub fn set_symmetric_key(&mut self, key: &[u8]) -> Result<()>

Wraps the set_symmetric_key convenience for AeaContext.

Examples found in repository?
examples/10_aea_roundtrip.rs (line 35)
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}
Source

pub fn set_password(&mut self, password: &[u8]) -> Result<()>

Wraps the set_password convenience for AeaContext.

Source

pub fn set_signing_public_key(&mut self, key: &[u8]) -> Result<()>

Wraps the set_signing_public_key convenience for AeaContext.

Source

pub fn set_signing_private_key(&mut self, key: &[u8]) -> Result<()>

Wraps AEAEncryptionOutputStreamOpen.

Source

pub fn set_recipient_public_key(&mut self, key: &[u8]) -> Result<()>

Wraps AEAEncryptionOutputStreamOpen.

Source

pub fn set_recipient_private_key(&mut self, key: &[u8]) -> Result<()>

Wraps AEAEncryptionOutputStreamOpen.

Source

pub fn set_main_key(&mut self, key: &[u8]) -> Result<()>

Wraps AEAEncryptionOutputStreamOpen.

Source

pub fn encryption_output_stream( &self, encrypted_stream: ByteStream, flags: ArchiveFlags, n_threads: i32, ) -> Result<ByteStream>

Wraps AEAEncryptionOutputStreamOpen.

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 = 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}
Source

pub fn encryption_output_stream_existing( &self, encrypted_stream: ByteStream, flags: ArchiveFlags, n_threads: i32, ) -> Result<ByteStream>

Wraps AEAEncryptionOutputStreamOpenExisting.

Source

pub fn decryption_input_stream( &mut self, encrypted_stream: ByteStream, flags: ArchiveFlags, n_threads: i32, ) -> Result<ByteStream>

Wraps AEADecryptionInputStreamOpen.

Examples found in repository?
examples/10_aea_roundtrip.rs (line 36)
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}
Source

pub fn decryption_random_access_input_stream( &mut self, encrypted_stream: ByteStream, alloc_limit: usize, flags: ArchiveFlags, n_threads: i32, ) -> Result<ByteStream>

Wraps AEADecryptionRandomAccessInputStreamOpen.

Source

pub fn close_encryption_output_stream( &mut self, stream: &mut ByteStream, ) -> Result<()>

Wraps AEAEncryptionOutputStreamCloseAndUpdateContext.

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 = 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}
Source

pub fn sign_stream(&self, stream: &mut ByteStream) -> Result<()>

Wraps AEAStreamSign.

Trait Implementations§

Source§

impl Debug for AeaContext

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Drop for AeaContext

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.