hex

package
v0.0.0-...-890d697 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 7, 2022 License: BSD-3-Clause Imports: 3 Imported by: 0

Documentation

Overview

Package hex implements constant-time hexadecimal encoding and decoding.

Index

Constants

This section is empty.

Variables

View Source
var ErrLength = hex.ErrLength

Functions

func Decode

func Decode(dst, src []byte) (int, error)

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

func DecodeString(s string) ([]byte, error)

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 DecodedLen(n int) int

func Encode

func Encode(dst, src []byte) int

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

func EncodeToString(src []byte) string

EncodeToString returns the hexadecimal encoding of src.

Encode runs in constant time for the length of src.

func EncodedLen

func EncodedLen(n int) int

EncodedLen returns the length of an encoding of n source bytes. Specifically, it returns n * 2.

func NewDecoder

func NewDecoder(r io.Reader) io.Reader

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.

func NewEncoder

func NewEncoder(w io.Writer) io.Writer

NewEncoder returns an io.Writer that writes lowercase hexadecimal characters to w.

Types

type InvalidByteError

type InvalidByteError = hex.InvalidByteError

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL