Documentation ¶
Index ¶
- Constants
- Variables
- func FormatContent(b []byte) []byte
- func FormatContentString(s string) string
- func NormalizeByte(b byte) byte
- func NormalizeBytes(b []byte, buf *bytes.Buffer)
- func NormalizeContent(content []byte) []byte
- func NormalizeContentString(content string) []byte
- func NormalizeFirstLine(b []byte) []byte
- func PrefixContent(content []byte, sealDate string) []byte
- func RemoveBlankRows(b []byte) []byte
- func RemoveBlankRowsString(s string) string
- type HmacSealer
- func (hm *HmacSealer) AddData(data string) error
- func (hm *HmacSealer) AddDataBytes(data []byte) error
- func (hm *HmacSealer) Calculate() (err error)
- func (hm *HmacSealer) CheckKvv(kvv string) error
- func (hm *HmacSealer) EnsureNoSignature() error
- func (hm *HmacSealer) GenerateKvv() error
- func (hm *HmacSealer) GetKvv() string
- func (hm *HmacSealer) GetKvvBgFormat() string
- func (hm *HmacSealer) GetMac() string
- func (hm *HmacSealer) GetMacBgFormat() string
- func (hm *HmacSealer) GetMacBytes() []byte
- func (hm *HmacSealer) GetSignedContent() string
- func (hm *HmacSealer) SetData(data string) error
- func (hm *HmacSealer) SetDataBytes(data []byte) error
- func (hm *HmacSealer) SetHashFunction(hashFunc func() hash.Hash) error
- func (hm *HmacSealer) SetKey(key string) error
- func (hm *HmacSealer) SetKeyBytes(key []byte) error
- func (hm *HmacSealer) SetSealDate(date string) error
- func (hm *HmacSealer) UpdateFormatted() error
- func (hm *HmacSealer) Validate() (err error)
Constants ¶
const NormCrChar = 13
const NormLfChar = 10
const NormLowerLimit = 32
const NormOutOfRangeReplacement = 195
const NormUpperLimit = 126
Variables ¶
var NormSpecialReplacement map[int]int = map[int]int{
201: 64,
196: 91,
214: 92,
197: 93,
220: 94,
233: 96,
228: 123,
246: 124,
229: 125,
252: 126,
}
var RegexMatchEmptyLines = regexp.MustCompile(`\r\n[\s\t]*\r\n`)
Functions ¶
func FormatContent ¶
func FormatContentString ¶
func NormalizeContent ¶
func NormalizeContentString ¶
func NormalizeFirstLine ¶
Ensure that the first line of the content is a maximum of 80 characters long
func PrefixContent ¶
func RemoveBlankRows ¶
func RemoveBlankRowsString ¶
Types ¶
type HmacSealer ¶
type HmacSealer struct { Key []byte KeyVer []byte Hash func() hash.Hash Mac []byte SealDate string OriginalData []byte PrefixedData []byte FormattedData []byte NormalizedData []byte }
Key: the hex-decoded HMAC key used to seal the file KeyVer (KVV, KeyVerificationValue) is the the value used to verify the key, obtained by sealing the string "00000000" HashFunc: the hash function used to calculate the HMAC seal, default is sha256
func (*HmacSealer) AddData ¶
func (hm *HmacSealer) AddData(data string) error
Append given string to the data
func (*HmacSealer) AddDataBytes ¶
func (hm *HmacSealer) AddDataBytes(data []byte) error
Append given byte slice to the data
func (*HmacSealer) Calculate ¶
func (hm *HmacSealer) Calculate() (err error)
Calculate the HMAC seal MAC for the data
func (*HmacSealer) CheckKvv ¶
func (hm *HmacSealer) CheckKvv(kvv string) error
Check the KVV value against a provided value
func (*HmacSealer) EnsureNoSignature ¶
func (hm *HmacSealer) EnsureNoSignature() error
func (*HmacSealer) GenerateKvv ¶
func (hm *HmacSealer) GenerateKvv() error
Generate and store the KVV Value
func (*HmacSealer) GetKvv ¶
func (hm *HmacSealer) GetKvv() string
Get the KVV value as a hex string (64 characters)
func (*HmacSealer) GetKvvBgFormat ¶
func (hm *HmacSealer) GetKvvBgFormat() string
Get the KVV value as a hex string (32 characters) formatted for use in BG files
func (*HmacSealer) GetMac ¶
func (hm *HmacSealer) GetMac() string
Get the full MAC as a hex string (64 characters)
func (*HmacSealer) GetMacBgFormat ¶
func (hm *HmacSealer) GetMacBgFormat() string
Get the calculated HMAC seal MAC as a hex string (32 characters) formatted for use in BG files
func (*HmacSealer) GetMacBytes ¶
func (hm *HmacSealer) GetMacBytes() []byte
Get the calculated HMAC seal MAC as a bytestring
func (*HmacSealer) GetSignedContent ¶
func (hm *HmacSealer) GetSignedContent() string
func (*HmacSealer) SetData ¶
func (hm *HmacSealer) SetData(data string) error
Replace the data with a given string
func (*HmacSealer) SetDataBytes ¶
func (hm *HmacSealer) SetDataBytes(data []byte) error
Replace the data with a given byte slice
func (*HmacSealer) SetHashFunction ¶
func (hm *HmacSealer) SetHashFunction(hashFunc func() hash.Hash) error
Set the hash function used to hash the file contents
func (*HmacSealer) SetKey ¶
func (hm *HmacSealer) SetKey(key string) error
Set the key used to seal the file
func (*HmacSealer) SetKeyBytes ¶
func (hm *HmacSealer) SetKeyBytes(key []byte) error
Set the key used to seal the file as a byte array
func (*HmacSealer) SetSealDate ¶
func (hm *HmacSealer) SetSealDate(date string) error
Set a custom seal date
func (*HmacSealer) UpdateFormatted ¶
func (hm *HmacSealer) UpdateFormatted() error
Update the values of the Formatted/Normalized data fields Formatted will ensure the correct line endings are present Normalized will normalize the content for HMAC signature
func (*HmacSealer) Validate ¶
func (hm *HmacSealer) Validate() (err error)
Validate that everything is in place to calculate the HMAC seal