From d5d9e06f47a5a20d86cfc87cbeecec4dc1e74cfd Mon Sep 17 00:00:00 2001 From: Armani Ferrante Date: Tue, 9 Oct 2018 21:23:55 +0000 Subject: [PATCH] Add confidential prefix check utility --- key-manager/common/src/confidential.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/key-manager/common/src/confidential.rs b/key-manager/common/src/confidential.rs index 9bfa041728a..ec0d36459c7 100644 --- a/key-manager/common/src/confidential.rs +++ b/key-manager/common/src/confidential.rs @@ -6,6 +6,25 @@ use ekiden_core::mrae::sivaessha2; use super::{PrivateKeyType, PublicKeyType, EMPTY_PRIVATE_KEY, EMPTY_PUBLIC_KEY}; use sodalite; +static PREFIX_LEN: usize = 12; + +pub fn is_encrypted(data: &[u8]) -> bool { + if data.len() < PREFIX_LEN { + return false; + } + let prefix = &data[..PREFIX_LEN]; + // u8 representation of "confidential" + let confidential_prefix = [99, 111, 110, 102, 105, 100, 101, 110, 116, 105, 97, 108]; + return prefix == confidential_prefix; +} + +pub fn remove_prefix(data: Vec) -> Vec { + if data.len() < PREFIX_LEN { + return data; + } + data[PREFIX_LEN..].to_vec() +} + pub fn encrypt( plaintext: Vec, nonce: Vec,