Documentation
¶
Index ¶
Constants ¶
const ( // Base36Uint64Width is the maximum number of base36 characters needed to represent any uint64: // ceil(64 / log2(36)) = 13. Base36Uint64Width = 13 // Base62Uint64Width is the maximum number of base62 characters needed to represent any uint64: // ceil(64 / log2(62)) = 11. Base62Uint64Width = 11 )
Variables ¶
var ( // Base36 encodes input as base36. Base36 = NewEncoder(36) // Base62 encodes input as base62. Base62 = NewEncoder(62) )
var ( // Base36Sha224 hashes input with sha224 and encodes the digest as lowercase base36. Base36Sha224 = Hasher{/* contains filtered or unexported fields */} // Base62Sha224 hashes input with sha224 and encodes the digest as lowercase base62. Base62Sha224 = Hasher{/* contains filtered or unexported fields */} )
Functions ¶
func Random256BitsString ¶
func Random256BitsString() string
Random256BitsString is a convenience function for calling RandomBitsString(256). Callers that need a random string should use this function unless they have a very good reason to need a different amount of entropy.
func RandomBits ¶
RandomBits returns a random byte slice with at least the requested bits of entropy. Callers should avoid using a value less than 256 unless they have a very good reason.
func RandomBitsString ¶
RandomBitsString returns a random string with at least the requested bits of entropy. It uses RawURLEncoding to ensure we do not get / characters or trailing ='s.
Types ¶
type Encoder ¶
type Encoder struct {
// contains filtered or unexported fields
}
Encoder produces base-N encodings of byte slices and uint64s.
func NewEncoder ¶
NewEncoder returns an Encoder for the given base.
func (Encoder) Bytes ¶
Bytes returns the base-N encoding of b. Leading zero bytes in b are dropped; use Encoder.BytesPad to preserve them.
func (Encoder) BytesPad ¶
BytesPad returns the base-N encoding of b, with one pad character prepended for each leading zero byte in b. An empty or all-zero b is encoded as a string of len(b) pad characters.
func (Encoder) Int ¶
Int returns the base-N encoding of v's big-endian byte representation. The output is variable-length, use Encoder.IntPad for fixed-length.
type Hasher ¶
type Hasher struct {
// contains filtered or unexported fields
}
Hasher computes sha224(input) and encodes the digest with its embedded encoder.
func (Hasher) Bytes ¶
Bytes calculates the sha224 hash of b and returns its base-N encoding. Leading zero bytes in the digest are dropped; use Hasher.BytesPad to preserve them.
func (Hasher) BytesPad ¶
BytesPad calculates the sha224 hash of b and returns its base-N encoding, with one pad character prepended for each leading zero byte in the digest.
func (Hasher) String ¶
String calculates the sha224 hash of s and returns its base-N encoding. Leading zero bytes in the digest are dropped; use Hasher.StringPad to preserve them.