Standard library · Cryptography
crypto/sha1
Imported as import "crypto/sha1" as sha1, its names are then sha1.…. Every signature below is the one the checker infers.
SHA-1 and base64, written in Rill. The WebSocket handshake needs both, and they are a fair test of the language's bit operations: everything here is 32-bit arithmetic emulated on 64-bit integers by masking after each step.
import "text/str" as str str.hex_encode(sha1.sha1("abc")) # => a9993e364706816aba3e25717850c26c9cd0d89d sha1.base64(sha1.sha1("abc")) # => qZk+NkcGgWq6PiVxeFDCbJzQ2J0=
Types
Digest
Digest(a: Int, b: Int, c: Int, d: Int, e: Int)
Functions
fn sha1(msg: Str) -> Str
The digest as 20 raw bytes.
import "text/str" as str str.hex_encode(sha1.sha1("")) # => da39a3ee5e6b4b0d3255bfef95601890afd80709 #sha1.sha1("anything") # => 20
fn base64(s: Str) -> Str
sha1.base64("hello") # => aGVsbG8= sha1.base64("") # =>