Documentation ¶
Index ¶
- Constants
- Variables
- func DoRawDefaultHash(p []byte) (HashType, RawDefaultHash)
- type HMAC
- func (hmac HMAC) Bytes() []byte
- func (hmac HMAC) IsValid() bool
- func (hmac HMAC) MarshalBinary() (data []byte, err error)
- func (hmac HMAC) MarshalText() ([]byte, error)
- func (hmac HMAC) String() string
- func (hmac *HMAC) UnmarshalBinary(data []byte) error
- func (hmac *HMAC) UnmarshalText(data []byte) error
- func (hmac HMAC) Verify(key, buf []byte) error
- type Hash
- func (h Hash) Bytes() []byte
- func (h Hash) GetHashType() HashType
- func (h Hash) IsValid() bool
- func (h Hash) MarshalBinary() (data []byte, err error)
- func (h Hash) MarshalText() ([]byte, error)
- func (h *Hash) Size() int
- func (h Hash) String() string
- func (h *Hash) UnmarshalBinary(data []byte) error
- func (h *Hash) UnmarshalText(data []byte) error
- func (h Hash) Verify(buf []byte) error
- type HashMismatchError
- type HashType
- type InvalidHashError
- type RawDefaultHash
- type UnknownHashTypeError
Constants ¶
const ( // MinHashByteLength is the minimum number of bytes a valid // keybase hash can be, including the 1 byte for the type. MinHashByteLength = 33 // DefaultHashByteLength is the number of bytes in a default // keybase hash. DefaultHashByteLength = 1 + sha256.Size // MaxHashByteLength is the maximum number of bytes a valid // keybase hash can be, including the 1 byte for the type. MaxHashByteLength = 129 // MinHashStringLength is the minimum number of characters in // the string representation (hex encoding) of a valid keybase // hash. MinHashStringLength = 2 * MinHashByteLength // DefaultHashStringLength is the number of characters in the // string representation of a default keybase hash. DefaultHashStringLength = 2 * DefaultHashByteLength // MaxHashStringLength is the maximum number of characters the // string representation of a valid keybase hash can be. MaxHashStringLength = 2 * MaxHashByteLength )
Variables ¶
var DefaultHashNew = sha256.New
DefaultHashNew is a function that creates a new hash.Hash object with the default hash.
var MaxDefaultHash = RawDefaultHash{
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
}
MaxDefaultHash is the maximum value of RawDefaultHash
Functions ¶
func DoRawDefaultHash ¶
func DoRawDefaultHash(p []byte) (HashType, RawDefaultHash)
DoRawDefaultHash computes the default keybase hash of the given data, and returns the type and the raw hash bytes.
Types ¶
type HMAC ¶
type HMAC struct {
// contains filtered or unexported fields
}
HMAC is the type of a keybase hash that is an HMAC.
All the constants for Hash also apply to HMAC.
func DefaultHMAC ¶
DefaultHMAC computes the HMAC with the given key of the given data using the default hash.
func (HMAC) IsValid ¶
IsValid returns whether the HMAC is valid. Note that an HMAC with an unknown version is still valid.
func (HMAC) MarshalBinary ¶
MarshalBinary implements the encoding.BinaryMarshaler interface for HMAC. Returns an error if the HMAC is invalid and not the zero HMAC.
func (HMAC) MarshalText ¶
MarshalText implements the encoding.TextMarshaler interface for HMAC.
func (*HMAC) UnmarshalBinary ¶
UnmarshalBinary implements the encoding.BinaryUnmarshaler interface for HMAC. Returns an error if the given byte array is non-empty and the HMAC is invalid.
func (*HMAC) UnmarshalText ¶
UnmarshalText implements the encoding.TextUnmarshaler interface for HMAC.
type Hash ¶
type Hash struct {
// contains filtered or unexported fields
}
Hash is the type of a keybase hash.
func DefaultHash ¶
DefaultHash computes the hash of the given data with the default hash type.
func HashFromBytes ¶
HashFromBytes creates a hash from the given byte array. If the returned error is nil, the returned Hash is valid.
func HashFromRaw ¶
HashFromRaw creates a hash from a type and raw hash data. If the returned error is nil, the returned Hash is valid.
func HashFromString ¶
HashFromString creates a hash from the given string. If the returned error is nil, the returned Hash is valid.
func (Hash) GetHashType ¶
GetHashType returns the type of this hash.
func (Hash) IsValid ¶
IsValid returns whether the hash is valid. Note that a hash with an unknown version is still valid.
func (Hash) MarshalBinary ¶
MarshalBinary implements the encoding.BinaryMarshaler interface for Hash. Returns an error if the hash is invalid and not the zero hash.
func (Hash) MarshalText ¶
MarshalText implements the encoding.TextMarshaler interface for Hash.
func (*Hash) UnmarshalBinary ¶
UnmarshalBinary implements the encoding.BinaryUnmarshaler interface for Hash. Returns an error if the given byte array is non-empty and the hash is invalid.
func (*Hash) UnmarshalText ¶
UnmarshalText implements the encoding.TextUnmarshaler interface for Hash.
type HashMismatchError ¶
HashMismatchError is returned whenever a hash mismatch is detected.
func (HashMismatchError) Error ¶
func (e HashMismatchError) Error() string
type HashType ¶
type HashType byte
HashType is the type of a keybase hash.
const ( // InvalidHash is the zero HashType value, which is invalid. InvalidHash HashType = 0 // SHA256Hash is the type of a SHA256 hash. SHA256Hash HashType = 1 // SHA256HashV2 is the type of a SHA256 hash over V2-encrypted data. SHA256HashV2 HashType = 2 // MaxHashType is the highest-supported hash type. MaxHashType HashType = SHA256HashV2 )
const DefaultHashType HashType = SHA256Hash
DefaultHashType is the current default keybase hash type.
type InvalidHashError ¶
type InvalidHashError struct {
H Hash
}
InvalidHashError is returned whenever an invalid hash is detected.
func (InvalidHashError) Error ¶
func (e InvalidHashError) Error() string
type RawDefaultHash ¶
RawDefaultHash is the type for the raw bytes of a default keybase hash. This is exposed for use as in-memory keys.
func (*RawDefaultHash) Copy ¶
func (rdh *RawDefaultHash) Copy() *RawDefaultHash
Copy returns a copied RawDefaultHash
type UnknownHashTypeError ¶
type UnknownHashTypeError struct {
T HashType
}
UnknownHashTypeError is returned whenever a hash with an unknown hash type is attempted to be used for verification.
func (UnknownHashTypeError) Error ¶
func (e UnknownHashTypeError) Error() string