Skip to content

crypto.sha1 #

Copyright (c) 2019-2024 Alexander Medvednikov. All rights reserved. Use of this source code is governed by an MIT license that can be found in the LICENSE file. Package sha1 implements the SHA-1 hash algorithm as defined in RFC 3174. SHA-1 is cryptographically broken and should not be used for secure applications. Based off: https://github.com/golang/go/blob/master/src/crypto/sha1 Last commit: https://github.com/golang/go/commit/3ce865d7a0b88714cc433454ae2370a105210c01

Constants #

const size = 20

The size of a SHA-1 checksum in bytes.

const block_size = 64

The blocksize of SHA-1 in bytes.

fn hexhash #

fn hexhash(s string) string

hexhash returns a hexadecimal SHA1 hash sum string of s.

fn new #

fn new() &Digest

new returns a new Digest (implementing hash.Hash) computing the SHA1 checksum.

fn sum #

fn sum(data []u8) []u8

sum returns the SHA-1 checksum of the bytes passed in data.

fn (Digest) free #

@[unsafe]
fn (mut d Digest) free()

free the resources taken by the Digest d

fn (Digest) reset #

fn (mut d Digest) reset()

reset the state of the Digest d

fn (Digest) copy_from #

fn (mut d Digest) copy_from(src &Digest)

copy_from overwrites the state of d with the state of src, without allocating. Afterwards d continues from the data that was written to src so far.

fn (Digest) write #

@[manualfree]
fn (mut d Digest) write(p_ []u8) !int

write writes the contents of p_ to the internal hash representation.

fn (Digest) sum #

fn (d &Digest) sum(b_in []u8) []u8

sum returns a copy of the generated sum of the bytes in b_in.

fn (Digest) checksum_into #

@[direct_array_access]
fn (mut d Digest) checksum_into(mut out []u8)

checksum_into finalizes d and writes its checksum into the first size bytes of out, without allocating. It panics if out is shorter than size. Like sum, it consumes the state of d: call reset() or copy_from() before writing to d again.

fn (Digest) size #

fn (d &Digest) size() int

size returns the size of the checksum in bytes.

fn (Digest) block_size #

fn (d &Digest) block_size() int

block_size returns the block size of the checksum in bytes.