Skip to content
CryoCryo home
Stdlibhash

sha1

import std::hash::sha1; · source

SHA-1, as RFC 3174 defines it, in pure Cryo, with the same shape as sha256.

SHA-1 is cryptographically broken for collision resistance. It ships here only because protocols name it — the WebSocket handshake (RFC 6455) hard-codes it for the Sec-WebSocket-Accept value. Do not use it as a security primitive. Having a pure Cryo implementation is what keeps plain ws:// free of any external crypto dependency — no OpenSSL link required.

For a cryptographic hash, use sha256. For hashing in the non-cryptographic sense — map keys, fingerprints — use core::hash. For key material, tokens, and nonces, use random::SecureRng.

Types

Sha1

type struct Sha1 {
    private state:          [u32; 5];
    private block:          [u8; 64];
    private buffered:       i64;
    private message_length: u64;
}

A computation in progress: update feeds the message in pieces and finish gives the digest; Sha1::digest hashes one message held whole.

Constructors

static new() -> Sha1;

A computation over the empty message.

Static functions

static digest(data: &Slice<u8>) -> Sha1Digest;

The digest of data, held whole.

Methods

update(mut &this, data: &Slice<u8>) -> void;

Append data to the message.

finish(mut this) -> Sha1Digest;

Close the message and give its digest.

Sha1Digest

type struct Sha1Digest with [Eq] {
    private bytes: [u8; 20];
}

The hash's 20 bytes. It displays, and to_hex writes it, as 40 lowercase hexadecimal digits.

Methods

as_bytes(&this) -> &Slice<u8>;

The digest's bytes.

to_hex(&this) -> String;

The digest as 40 lowercase hexadecimal digits.

Trait implementations

implement trait Display for struct Sha1Digest

Constants

const DIGEST_LENGTH: i64 = 20;
const BLOCK_LENGTH:  i64 = 64;