usecrate::b64; usecrate::credentials::Key; usecrate::error::*; use base64::Engine; use std::io::Write; use std::ops::Deref; use std::time::{SystemTime, UNIX_EPOCH};
/// The kind of MAC calcuation (corresponding to the first line of the message) pubenum MacType {
Header,
Response,
Bewit,
}
/// Mac represents a message authentication code, the signature in a Hawk transaction. /// /// This class supports creating Macs using the Hawk specification, and comparing Macs /// using a cosntant-time comparison (thus preventing timing side-channel attacks). #[derive(Debug, Clone)] pubstruct Mac(Vec<u8>);
impl Mac { pubfn new(
mac_type: MacType,
key: &Key,
ts: SystemTime,
nonce: &str,
method: &str,
host: &str,
port: u16,
path: &str,
hash: Option<&[u8]>,
ext: Option<&str>,
) -> Result<Mac> { // Note: there's a \n after each item. letmut buffer: Vec<u8> = Vec::with_capacity( 15 + 1 + // mac_type (worst case since it doesn't really matter) 10 + 1 + // ts (in practice this will be 10 bytes)
nonce.len() + 1 +
host.len() + 1 + 6 + 1 + // Longer than 6 bytes of port seems very unlikely
path.len() + 1 +
hash.map_or(0, |h| h.len() * 4 / 3) + 1 +
ext.map_or(0, str::len) + 1,
);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.