Documentation
¶
Overview ¶
Package hex implements constant-time hexadecimal encoding and decoding.
Index ¶
- Variables
- func Decode(dst, src []byte) (int, error)
- func DecodeString(s string) ([]byte, error)
- func DecodedLen(n int) int
- func Encode(dst, src []byte) int
- func EncodeToString(src []byte) string
- func EncodedLen(n int) int
- func NewDecoder(r io.Reader) io.Reader
- func NewEncoder(w io.Writer) io.Writer
- type InvalidByteError
Constants ¶
This section is empty.
Variables ¶
var ErrLength = hex.ErrLength
Functions ¶
func Decode ¶
Decode decodes src into DecodedLen(len(src)) bytes, returning the actual number of bytes written to dst.
Decode expects that src contains only hexadecimal characters and that src has even length. If the input is malformed, Decode returns the number of bytes decoded before the error.
Decode runs in constant time for the length of src.
func DecodeString ¶
DecodeString returns the bytes represented by the hexadecimal string s.
DecodeString expects that src contains only hexadecimal characters and that src has even length. If the input is malformed, DecodeString returns the bytes decoded before the error.
DecodeString runs in constant time for the length of s.
func DecodedLen ¶
func Encode ¶
Encode encodes src into EncodedLen(len(src)) bytes of dst. As a convenience, it returns the number of bytes written to dst, but this value is always EncodedLen(len(src)).
Encode runs in constant time for the length of src.
func EncodeToString ¶
EncodeToString returns the hexadecimal encoding of src.
Encode runs in constant time for the length of src.
func EncodedLen ¶
EncodedLen returns the length of an encoding of n source bytes. Specifically, it returns n * 2.
func NewDecoder ¶
NewDecoder returns an io.Reader that decodes hexadecimal characters from r.
NewDecoder expects that r contain only an even number of hexadecimal characters.
The first call to Read that encounters malformed hexadecimal characters will return a non-nil error. This means that the io.Reader does not operate in constant time over the entire stream, but rather for each chunk read from r.
Types ¶
type InvalidByteError ¶
type InvalidByteError = hex.InvalidByteError