summaryrefslogtreecommitdiffstats
path: root/openpgp/src/crypto/aead.rs
diff options
context:
space:
mode:
Diffstat (limited to 'openpgp/src/crypto/aead.rs')
-rw-r--r--openpgp/src/crypto/aead.rs9
1 files changed, 9 insertions, 0 deletions
diff --git a/openpgp/src/crypto/aead.rs b/openpgp/src/crypto/aead.rs
index 713b320e..61cfd7f7 100644
--- a/openpgp/src/crypto/aead.rs
+++ b/openpgp/src/crypto/aead.rs
@@ -1,4 +1,5 @@
use std::cmp;
+use std::convert::TryInto;
use std::fmt;
use std::io;
@@ -24,6 +25,14 @@ use crate::parse::Cookie;
/// malformed AEAD-encrypted messages.
const DANGER_DISABLE_AUTHENTICATION: bool = false;
+/// Converts a chunk size to a usize.
+pub(crate) fn chunk_size_usize(chunk_size: u64) -> Result<usize> {
+ chunk_size.try_into()
+ .map_err(|_| Error::InvalidOperation(
+ format!("AEAD chunk size exceeds size of \
+ virtual memory: {}", chunk_size)).into())
+}
+
impl AEADAlgorithm {
/// Returns the digest size of the AEAD algorithm.
pub fn digest_size(&self) -> Result<usize> {