mirror of
https://github.com/FiloSottile/age.git
synced 2026-01-07 12:35:14 +00:00
tests: add more tests for hmac and X25519 encodings
This commit is contained in:
@@ -30,6 +30,16 @@ var _, TestX25519Identity, _ = bech32.Decode(
|
||||
|
||||
var TestX25519Recipient, _ = curve25519.X25519(TestX25519Identity, curve25519.Basepoint)
|
||||
|
||||
func NotCanonicalBase64(s string) string {
|
||||
// Assuming there are spare zero bits at the end of the encoded bitstring,
|
||||
// the character immediately after in the alphabet compared to the last one
|
||||
// in the encoding will only flip the last bit to one, making the string a
|
||||
// non-canonical encoding of the same value.
|
||||
alphabet := "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
|
||||
idx := strings.IndexByte(alphabet, s[len(s)-1])
|
||||
return s[:len(s)-1] + string(alphabet[idx+1])
|
||||
}
|
||||
|
||||
type TestFile struct {
|
||||
Buf bytes.Buffer
|
||||
Rand func(n int) []byte
|
||||
@@ -64,6 +74,14 @@ func (f *TestFile) TextLine(s string) {
|
||||
f.Buf.WriteString("\n")
|
||||
}
|
||||
|
||||
func (f *TestFile) UnreadLine() string {
|
||||
buf := bytes.TrimSuffix(f.Buf.Bytes(), []byte("\n"))
|
||||
idx := bytes.LastIndex(buf[:len(buf)-1], []byte("\n")) + 1
|
||||
f.Buf.Reset()
|
||||
f.Buf.Write(buf[:idx])
|
||||
return string(buf[idx:])
|
||||
}
|
||||
|
||||
func (f *TestFile) VersionLine(v string) {
|
||||
f.TextLine("age-encryption.org/" + v)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user