use std::collections::HashMap;
use sha1::{Sha1, Digest};

/// The WebSocket protocol version, as defined by RFC 6455 to be 13.
pub const WEBSOCKET_PROTOCOL_VERSION: i32 = 13;

/// A type alias for a key-value header map
pub type HeaderMap = HashMap<String, String>;

pub(crate) fn derive_handshake_response(input: &str) -> String {
    let mut hasher = Sha1::new();
    hasher.update(input);
    hasher.update(b"258EAFA5-E914-47DA-95CA-C5AB0DC85B11");
    crate::b64::impl_b64::base64_encode(&hasher.finalize())
}

#[cfg(test)]
mod tests {
    use crate::handshake_common::derive_handshake_response;

    #[test]
    fn handshake_response_derivation() {
        assert_eq!(
            derive_handshake_response("dGhlIHNhbXBsZSBub25jZQ=="),
            "s3pPLMBiTxaQ9kYGzzhZRbK+xOo="
        )
    }
}