summaryrefslogtreecommitdiff
path: root/src/key/mod.rs
diff options
context:
space:
mode:
authorStuart Stock <stuart@int08h.com>2018-10-07 21:44:53 -0500
committerStuart Stock <stuart@int08h.com>2018-10-07 21:44:53 -0500
commita072d3c67efdcaf4a9d969150268ed0151febb60 (patch)
treee70233e8291aba17e01596b6b0a4f76f7568729c /src/key/mod.rs
parentf6b5c2cc2aa38751ce774264a9088311ea0da412 (diff)
downloadroughenough-a072d3c67efdcaf4a9d969150268ed0151febb60.zip
wip checkpoint; nearly round-trip kms
Diffstat (limited to 'src/key/mod.rs')
-rw-r--r--src/key/mod.rs29
1 files changed, 26 insertions, 3 deletions
diff --git a/src/key/mod.rs b/src/key/mod.rs
index b269af2..62c37a9 100644
--- a/src/key/mod.rs
+++ b/src/key/mod.rs
@@ -18,11 +18,16 @@
extern crate hex;
extern crate log;
+extern crate ring;
+extern crate std;
mod envelope;
mod longterm;
mod online;
+use std::error::Error;
+
+pub use self::envelope::EnvelopeEncryption;
pub use self::longterm::LongTermKey;
pub use self::online::OnlineKey;
@@ -41,17 +46,35 @@ pub enum KeyProtection {
GoogleKmsEnvelope,
}
-#[derive(Debug, PartialEq, Eq, PartialOrd, Hash, Clone, Copy)]
+#[derive(Debug, PartialEq, Eq, PartialOrd, Hash, Clone)]
pub enum KmsError {
- DecryptionFailed(String),
- EncryptionFailed(String),
+ OperationFailed(String),
InvalidConfiguration(String),
+ InvalidData(String),
InvalidKey(String),
}
+impl From<std::io::Error> for KmsError {
+ fn from(error: std::io::Error) -> Self {
+ KmsError::OperationFailed(error.description().to_string())
+ }
+}
+
+impl From<ring::error::Unspecified> for KmsError {
+ fn from(error: ring::error::Unspecified) -> Self {
+ KmsError::OperationFailed("unspecified ring cryptographic failure".to_string())
+ }
+}
+
/// Size of the Data Encryption Key (DEK) in bytes
pub const DEK_SIZE_BYTES: usize = 32;
+/// Size of the AEAD nonce in bytes
+pub const NONCE_SIZE_BYTES: usize = 12;
+
+/// Size of the AEAD authentication tag in bytes
+pub const TAG_SIZE_BYTES: usize = 16;
+
/// An unencrypted (plaintext) 256-bit Data Encryption Key (DEK).
type PlaintextDEK = Vec<u8>;