tests: add armor tests

This commit is contained in:
Filippo Valsorda 2022-07-03 10:04:07 +02:00
parent e84d74239e
commit 799c2bf8e8
60 changed files with 896 additions and 11 deletions

View file

@ -63,6 +63,7 @@ type TestFile struct {
comment string
identities []string
passphrases []string
armor bool
}
func NewTestFile() *TestFile {
@ -87,7 +88,7 @@ func (f *TestFile) TextLine(s string) {
func (f *TestFile) UnreadLine() string {
buf := bytes.TrimSuffix(f.Buf.Bytes(), []byte("\n"))
idx := bytes.LastIndex(buf[:len(buf)-1], []byte("\n")) + 1
idx := bytes.LastIndex(buf, []byte("\n")) + 1
f.Buf.Reset()
f.Buf.Write(buf[:idx])
return string(buf[idx:])
@ -122,6 +123,16 @@ func (f *TestFile) Body(body []byte) {
}
}
func (f *TestFile) Base64Padding() {
line := f.UnreadLine()
paddingLen := 4 - len(line)%4
if paddingLen == 4 {
paddingLen = 0
}
padding := strings.Repeat("=", paddingLen)
f.TextLine(line + padding)
}
func (f *TestFile) AEADBody(key, body []byte) {
aead, _ := chacha20poly1305.New(key)
f.Body(aead.Seal(nil, make([]byte, chacha20poly1305.NonceSize), body, nil))
@ -231,6 +242,11 @@ func (f *TestFile) ExpectHeaderFailure() {
f.expect = "header failure"
}
func (f *TestFile) ExpectArmorFailure() {
f.armor = true
f.expect = "armor failure"
}
func (f *TestFile) ExpectPayloadFailure() {
f.expect = "payload failure"
f.payload.Reset()
@ -255,6 +271,22 @@ func (f *TestFile) Comment(c string) {
f.comment = c
}
func (f *TestFile) BeginArmor(t string) {
f.armor = true
f.TextLine("-----BEGIN " + t + "-----")
}
func (f *TestFile) EndArmor(t string) {
f.armor = true
f.TextLine("-----END " + t + "-----")
}
func (f *TestFile) Bytes() []byte {
out := make([]byte, f.Buf.Len())
copy(out, f.Buf.Bytes())
return out
}
func (f *TestFile) Generate() {
fmt.Printf("expect: %s\n", f.expect)
if f.expect == "success" || f.expect == "payload failure" {
@ -267,6 +299,9 @@ func (f *TestFile) Generate() {
for _, p := range f.passphrases {
fmt.Printf("passphrase: %s\n", p)
}
if f.armor {
fmt.Printf("armored: yes\n")
}
if f.comment != "" {
fmt.Printf("comment: %s\n", f.comment)
}

BIN
testdata/testkit/armor vendored Normal file

Binary file not shown.

BIN
testdata/testkit/armor_crlf vendored Normal file

Binary file not shown.

BIN
testdata/testkit/armor_empty_line_begin vendored Normal file

Binary file not shown.

BIN
testdata/testkit/armor_empty_line_end vendored Normal file

Binary file not shown.

Binary file not shown.

BIN
testdata/testkit/armor_full_last_line vendored Normal file

Binary file not shown.

BIN
testdata/testkit/armor_garbage_encoded vendored Normal file

Binary file not shown.

BIN
testdata/testkit/armor_garbage_leading vendored Normal file

Binary file not shown.

BIN
testdata/testkit/armor_garbage_trailing vendored Normal file

Binary file not shown.

BIN
testdata/testkit/armor_header_crlf vendored Normal file

Binary file not shown.

BIN
testdata/testkit/armor_headers vendored Normal file

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
testdata/testkit/armor_long_line vendored Normal file

Binary file not shown.

BIN
testdata/testkit/armor_lowercase vendored Normal file

Binary file not shown.

BIN
testdata/testkit/armor_no_end_line vendored Normal file

Binary file not shown.

BIN
testdata/testkit/armor_no_eol vendored Normal file

Binary file not shown.

BIN
testdata/testkit/armor_no_match vendored Normal file

Binary file not shown.

BIN
testdata/testkit/armor_no_padding vendored Normal file

Binary file not shown.

BIN
testdata/testkit/armor_not_canonical vendored Normal file

Binary file not shown.

BIN
testdata/testkit/armor_pgp_checksum vendored Normal file

Binary file not shown.

BIN
testdata/testkit/armor_short_line vendored Normal file

Binary file not shown.

BIN
testdata/testkit/armor_whitespace_begin vendored Normal file

Binary file not shown.

BIN
testdata/testkit/armor_whitespace_end vendored Normal file

Binary file not shown.

BIN
testdata/testkit/armor_whitespace_eol vendored Normal file

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
testdata/testkit/armor_wrong_type vendored Normal file

Binary file not shown.

View file

@ -11,6 +11,7 @@ import (
"bytes"
"crypto/sha256"
"encoding/hex"
"errors"
"flag"
"io"
"log"
@ -21,6 +22,7 @@ import (
"testing"
"filippo.io/age"
"filippo.io/age/armor"
)
//go:generate go test -generate -run ^$
@ -81,6 +83,7 @@ func testVector(t *testing.T, test []byte) {
expect string
payloadHash *[32]byte
identities []age.Identity
armored bool
)
for {
@ -99,6 +102,7 @@ func testVector(t *testing.T, test []byte) {
case "success":
case "HMAC failure":
case "header failure":
case "armor failure":
case "payload failure":
case "no match":
default:
@ -123,6 +127,8 @@ func testVector(t *testing.T, test []byte) {
t.Fatal(err)
}
identities = append(identities, i)
case "armored":
armored = true
case "file key":
// Ignored.
case "comment":
@ -132,13 +138,23 @@ func testVector(t *testing.T, test []byte) {
}
}
r, err := age.Decrypt(bytes.NewReader(test), identities...)
var in io.Reader = bytes.NewReader(test)
if armored {
in = armor.NewReader(in)
}
r, err := age.Decrypt(in, identities...)
if err != nil && strings.HasSuffix(err.Error(), "bad header MAC") {
if expect == "HMAC failure" {
t.Log(err)
return
}
t.Fatalf("expected %s, got HMAC error", expect)
} else if e := new(armor.Error); errors.As(err, &e) {
if expect == "armor failure" {
t.Log(err)
return
}
t.Fatalf("expected %s, got: %v", expect, err)
} else if _, ok := err.(*age.NoIdentityMatchError); ok {
if expect == "no match" {
t.Log(err)
@ -151,19 +167,24 @@ func testVector(t *testing.T, test []byte) {
return
}
t.Fatalf("expected %s, got: %v", expect, err)
} else if expect != "success" && expect != "payload failure" {
} else if expect != "success" && expect != "payload failure" &&
expect != "armor failure" {
t.Fatalf("expected %s, got success", expect)
}
out, err := io.ReadAll(r)
if err != nil {
if expect == "payload failure" {
t.Log(err)
if payloadHash != nil && sha256.Sum256(out) != *payloadHash {
t.Error("partial payload hash mismatch")
}
return
}
if err != nil && expect == "success" {
t.Fatalf("expected %s, got: %v", expect, err)
} else if err != nil {
t.Log(err)
if expect == "armor failure" {
if e := new(armor.Error); !errors.As(err, &e) {
t.Errorf("expected armor.Error, got %T", err)
}
}
if payloadHash != nil && sha256.Sum256(out) != *payloadHash {
t.Error("partial payload hash mismatch")
}
return
} else if expect != "success" {
t.Fatalf("expected %s, got success", expect)
}

25
tests/armor.go Normal file
View file

@ -0,0 +1,25 @@
// Copyright 2022 The age Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build ignore
// +build ignore
package main
import "filippo.io/age/internal/testkit"
func main() {
f := testkit.NewTestFile()
f.VersionLine("v1")
f.X25519(testkit.TestX25519Recipient)
f.HMAC()
f.Payload("age")
file := f.Bytes()
f.Buf.Reset()
f.BeginArmor("AGE ENCRYPTED FILE")
f.Body(file)
f.Base64Padding()
f.EndArmor("AGE ENCRYPTED FILE")
f.Generate()
}

33
tests/armor_crlf.go Normal file
View file

@ -0,0 +1,33 @@
// Copyright 2022 The age Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build ignore
// +build ignore
package main
import (
"bytes"
"filippo.io/age/internal/testkit"
)
func main() {
f := testkit.NewTestFile()
f.VersionLine("v1")
f.X25519(testkit.TestX25519Recipient)
f.HMAC()
f.Payload("age")
file := f.Bytes()
f.Buf.Reset()
f.BeginArmor("AGE ENCRYPTED FILE")
f.Body(file)
f.Base64Padding()
f.EndArmor("AGE ENCRYPTED FILE")
armored := f.Bytes()
f.Buf.Reset()
f.Buf.Write(bytes.Replace(armored, []byte("\n"), []byte("\r\n"), -1))
f.Comment("CRLF is allowed as a end of line for armored files")
f.Generate()
}

View file

@ -0,0 +1,27 @@
// Copyright 2022 The age Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build ignore
// +build ignore
package main
import "filippo.io/age/internal/testkit"
func main() {
f := testkit.NewTestFile()
f.VersionLine("v1")
f.X25519(testkit.TestX25519Recipient)
f.HMAC()
f.Payload("age")
file := f.Bytes()
f.Buf.Reset()
f.BeginArmor("AGE ENCRYPTED FILE")
f.TextLine("")
f.Body(file)
f.Base64Padding()
f.EndArmor("AGE ENCRYPTED FILE")
f.ExpectArmorFailure()
f.Generate()
}

View file

@ -0,0 +1,27 @@
// Copyright 2022 The age Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build ignore
// +build ignore
package main
import "filippo.io/age/internal/testkit"
func main() {
f := testkit.NewTestFile()
f.VersionLine("v1")
f.X25519(testkit.TestX25519Recipient)
f.HMAC()
f.Payload("age")
file := f.Bytes()
f.Buf.Reset()
f.BeginArmor("AGE ENCRYPTED FILE")
f.Body(file)
f.Base64Padding()
f.TextLine("")
f.EndArmor("AGE ENCRYPTED FILE")
f.ExpectArmorFailure()
f.Generate()
}

View file

@ -0,0 +1,39 @@
// Copyright 2022 The age Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build ignore
// +build ignore
package main
import (
"strings"
"filippo.io/age/internal/testkit"
)
// See base64finl in RFC 7468.
// ; ...AB= <EOL> = <EOL> is not good, but is valid
func main() {
f := testkit.NewTestFile()
f.VersionLine("v1")
f.X25519(testkit.TestX25519Recipient)
f.HMAC()
f.Payload("age12")
file := f.Bytes()
f.Buf.Reset()
f.BeginArmor("AGE ENCRYPTED FILE")
f.Body(file)
f.Base64Padding()
line := f.UnreadLine()
if !strings.Contains(line, "==") {
panic("need two padding characters")
}
line = strings.Replace(line, "==", "=\n=", 1)
f.TextLine(line)
f.EndArmor("AGE ENCRYPTED FILE")
f.ExpectArmorFailure()
f.Generate()
}

View file

@ -0,0 +1,29 @@
// Copyright 2022 The age Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build ignore
// +build ignore
package main
import "filippo.io/age/internal/testkit"
func main() {
f := testkit.NewTestFile()
f.VersionLine("v1")
f.X25519(testkit.TestX25519Recipient)
f.HMAC()
f.Payload("age age age age age age age age age age ")
file := f.Bytes()
f.Buf.Reset()
f.BeginArmor("AGE ENCRYPTED FILE")
if len(file)%48 != 0 {
println(len(file) % 48)
panic("last line is not full")
}
f.Body(file)
f.UnreadLine() // Body leaves an empty line, PEM doesn't.
f.EndArmor("AGE ENCRYPTED FILE")
f.Generate()
}

View file

@ -0,0 +1,30 @@
// Copyright 2022 The age Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build ignore
// +build ignore
package main
import "filippo.io/age/internal/testkit"
func main() {
f := testkit.NewTestFile()
f.FileKey(testkit.LargeTestFileKey)
f.VersionLine("v1")
f.X25519(testkit.TestX25519Identity)
f.HMAC()
f.Nonce(testkit.LargeTestNonce)
f.PayloadChunkFinal(testkit.LargeTestFirstChunk)
f.Buf.Write(f.Rand(20))
f.ExpectPartialPayload(64 * 1024)
file := f.Bytes()
f.Buf.Reset()
f.BeginArmor("AGE ENCRYPTED FILE")
f.Body(file)
f.Base64Padding()
f.EndArmor("AGE ENCRYPTED FILE")
f.Comment("there is trailing garbage encoded after the final chunk")
f.Generate()
}

View file

@ -0,0 +1,27 @@
// Copyright 2022 The age Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build ignore
// +build ignore
package main
import "filippo.io/age/internal/testkit"
func main() {
f := testkit.NewTestFile()
f.VersionLine("v1")
f.X25519(testkit.TestX25519Recipient)
f.HMAC()
f.Payload("age")
file := f.Bytes()
f.Buf.Reset()
f.TextLine("garbage")
f.BeginArmor("AGE ENCRYPTED FILE")
f.Body(file)
f.Base64Padding()
f.EndArmor("AGE ENCRYPTED FILE")
f.ExpectArmorFailure()
f.Generate()
}

View file

@ -0,0 +1,27 @@
// Copyright 2022 The age Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build ignore
// +build ignore
package main
import "filippo.io/age/internal/testkit"
func main() {
f := testkit.NewTestFile()
f.VersionLine("v1")
f.X25519(testkit.TestX25519Recipient)
f.HMAC()
f.Payload("age")
file := f.Bytes()
f.Buf.Reset()
f.BeginArmor("AGE ENCRYPTED FILE")
f.Body(file)
f.Base64Padding()
f.EndArmor("AGE ENCRYPTED FILE")
f.TextLine("garbage")
f.ExpectArmorFailure()
f.Generate()
}

View file

@ -0,0 +1,35 @@
// Copyright 2022 The age Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build ignore
// +build ignore
package main
import (
"bytes"
"filippo.io/age/internal/testkit"
)
func main() {
f := testkit.NewTestFile()
f.VersionLine("v1")
f.X25519(testkit.TestX25519Identity)
hdr := f.Buf.Bytes()
f.Buf.Reset()
f.Buf.Write(bytes.Replace(hdr, []byte("\n"), []byte("\r\n"), -1))
f.HMAC()
f.Buf.WriteString(f.UnreadLine() + "\r\n")
f.Payload("age")
f.ExpectHeaderFailure()
f.Comment("lines in the header end with CRLF instead of LF")
file := f.Bytes()
f.Buf.Reset()
f.BeginArmor("AGE ENCRYPTED FILE")
f.Body(file)
f.Base64Padding()
f.EndArmor("AGE ENCRYPTED FILE")
f.Generate()
}

29
tests/armor_headers.go Normal file
View file

@ -0,0 +1,29 @@
// Copyright 2022 The age Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build ignore
// +build ignore
package main
import "filippo.io/age/internal/testkit"
func main() {
f := testkit.NewTestFile()
f.VersionLine("v1")
f.X25519(testkit.TestX25519Recipient)
f.HMAC()
f.Payload("age")
file := f.Bytes()
f.Buf.Reset()
f.BeginArmor("AGE ENCRYPTED FILE")
f.TextLine("Headers: are")
f.TextLine("Not: allowed")
f.TextLine("")
f.Body(file)
f.Base64Padding()
f.EndArmor("AGE ENCRYPTED FILE")
f.ExpectArmorFailure()
f.Generate()
}

View file

@ -0,0 +1,34 @@
// Copyright 2022 The age Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build ignore
// +build ignore
package main
import (
"strings"
"filippo.io/age/internal/testkit"
)
func main() {
f := testkit.NewTestFile()
f.VersionLine("v1")
f.X25519(testkit.TestX25519Recipient)
f.HMAC()
f.Payload("age")
file := f.Bytes()
f.Buf.Reset()
f.BeginArmor("AGE ENCRYPTED FILE")
f.Body(file)
f.Base64Padding()
begin, rest, _ := strings.Cut(string(f.Bytes()), "\n")
f.Buf.Reset()
f.TextLine(begin)
f.Buf.WriteString(rest[:4] + "*" + rest[5:])
f.EndArmor("AGE ENCRYPTED FILE")
f.ExpectArmorFailure()
f.Generate()
}

View file

@ -0,0 +1,28 @@
// Copyright 2022 The age Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build ignore
// +build ignore
package main
import "filippo.io/age/internal/testkit"
func main() {
f := testkit.NewTestFile()
f.VersionLine("v1")
f.X25519(testkit.TestX25519Recipient)
f.HMAC()
f.Payload("age")
file := f.Bytes()
f.Buf.Reset()
f.BeginArmor("AGE ENCRYPTED FILE")
f.Body(file)
f.Base64Padding()
line := f.UnreadLine()
f.TextLine("*" + line[1:])
f.EndArmor("AGE ENCRYPTED FILE")
f.ExpectArmorFailure()
f.Generate()
}

30
tests/armor_long_line.go Normal file
View file

@ -0,0 +1,30 @@
// Copyright 2022 The age Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build ignore
// +build ignore
package main
import (
"encoding/base64"
"filippo.io/age/internal/testkit"
)
func main() {
f := testkit.NewTestFile()
f.VersionLine("v1")
f.X25519(testkit.TestX25519Recipient)
f.HMAC()
f.Payload("age")
file := f.Bytes()
f.Buf.Reset()
f.BeginArmor("AGE ENCRYPTED FILE")
f.TextLine(base64.StdEncoding.EncodeToString(file))
f.Base64Padding()
f.EndArmor("AGE ENCRYPTED FILE")
f.ExpectArmorFailure()
f.Generate()
}

26
tests/armor_lowercase.go Normal file
View file

@ -0,0 +1,26 @@
// Copyright 2022 The age Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build ignore
// +build ignore
package main
import "filippo.io/age/internal/testkit"
func main() {
f := testkit.NewTestFile()
f.VersionLine("v1")
f.X25519(testkit.TestX25519Recipient)
f.HMAC()
f.Payload("age")
file := f.Bytes()
f.Buf.Reset()
f.BeginArmor("age ENCRYPTED FILE")
f.Body(file)
f.Base64Padding()
f.EndArmor("age ENCRYPTED FILE")
f.ExpectArmorFailure()
f.Generate()
}

View file

@ -0,0 +1,25 @@
// Copyright 2022 The age Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build ignore
// +build ignore
package main
import "filippo.io/age/internal/testkit"
func main() {
f := testkit.NewTestFile()
f.VersionLine("v1")
f.X25519(testkit.TestX25519Recipient)
f.HMAC()
f.Payload("age")
file := f.Bytes()
f.Buf.Reset()
f.BeginArmor("AGE ENCRYPTED FILE")
f.Body(file)
f.Base64Padding()
f.ExpectArmorFailure()
f.Generate()
}

26
tests/armor_no_eol.go Normal file
View file

@ -0,0 +1,26 @@
// Copyright 2022 The age Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build ignore
// +build ignore
package main
import "filippo.io/age/internal/testkit"
func main() {
f := testkit.NewTestFile()
f.VersionLine("v1")
f.X25519(testkit.TestX25519Recipient)
f.HMAC()
f.Payload("age")
file := f.Bytes()
f.Buf.Reset()
f.BeginArmor("AGE ENCRYPTED FILE")
f.Body(file)
f.Base64Padding()
f.Buf.WriteString("-----END AGE ENCRYPTED FILE-----")
f.Comment("there is no end of line at the end of the file")
f.Generate()
}

28
tests/armor_no_match.go Normal file
View file

@ -0,0 +1,28 @@
// Copyright 2022 The age Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build ignore
// +build ignore
package main
import "filippo.io/age/internal/testkit"
func main() {
f := testkit.NewTestFile()
f.VersionLine("v1")
identity := f.Rand(32)
f.X25519RecordIdentity(identity)
f.X25519NoRecordIdentity(testkit.TestX25519Recipient)
f.HMAC()
f.Payload("age")
f.ExpectNoMatch()
file := f.Bytes()
f.Buf.Reset()
f.BeginArmor("AGE ENCRYPTED FILE")
f.Body(file)
f.Base64Padding()
f.EndArmor("AGE ENCRYPTED FILE")
f.Generate()
}

29
tests/armor_no_padding.go Normal file
View file

@ -0,0 +1,29 @@
// Copyright 2022 The age Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build ignore
// +build ignore
package main
import "filippo.io/age/internal/testkit"
func main() {
f := testkit.NewTestFile()
f.VersionLine("v1")
f.X25519(testkit.TestX25519Recipient)
f.HMAC()
f.Payload("age")
file := f.Bytes()
f.Buf.Reset()
f.BeginArmor("AGE ENCRYPTED FILE")
if len(file)%3 == 0 {
panic("no need for padding")
}
f.Body(file)
f.EndArmor("AGE ENCRYPTED FILE")
f.ExpectArmorFailure()
f.Comment("missing base64 padding")
f.Generate()
}

View file

@ -0,0 +1,28 @@
// Copyright 2022 The age Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build ignore
// +build ignore
package main
import "filippo.io/age/internal/testkit"
func main() {
f := testkit.NewTestFile()
f.VersionLine("v1")
f.X25519(testkit.TestX25519Recipient)
f.HMAC()
f.Payload("age")
file := f.Bytes()
f.Buf.Reset()
f.BeginArmor("AGE ENCRYPTED FILE")
f.Body(file)
f.TextLine(testkit.NotCanonicalBase64(f.UnreadLine()))
f.Base64Padding()
f.EndArmor("AGE ENCRYPTED FILE")
f.ExpectArmorFailure()
f.Comment("base64 is not canonical")
f.Generate()
}

View file

@ -0,0 +1,29 @@
// Copyright 2022 The age Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build ignore
// +build ignore
package main
import (
"filippo.io/age/internal/testkit"
"golang.org/x/crypto/openpgp/armor"
)
func main() {
f := testkit.NewTestFile()
f.VersionLine("v1")
f.X25519(testkit.TestX25519Recipient)
f.HMAC()
f.Payload("age")
file := f.Bytes()
f.Buf.Reset()
w, _ := armor.Encode(&f.Buf, "AGE ENCRYPTED FILE", nil)
w.Write(file)
w.Close()
f.Buf.WriteString("\n")
f.ExpectArmorFailure()
f.Generate()
}

27
tests/armor_short_line.go Normal file
View file

@ -0,0 +1,27 @@
// Copyright 2022 The age Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build ignore
// +build ignore
package main
import "filippo.io/age/internal/testkit"
func main() {
f := testkit.NewTestFile()
f.VersionLine("v1")
f.X25519(testkit.TestX25519Recipient)
f.HMAC()
f.Payload("age")
file := f.Bytes()
f.Buf.Reset()
f.BeginArmor("AGE ENCRYPTED FILE")
f.Body(file[:12])
f.Body(file[12:])
f.Base64Padding()
f.EndArmor("AGE ENCRYPTED FILE")
f.ExpectArmorFailure()
f.Generate()
}

View file

@ -0,0 +1,26 @@
// Copyright 2022 The age Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build ignore
// +build ignore
package main
import "filippo.io/age/internal/testkit"
func main() {
f := testkit.NewTestFile()
f.VersionLine("v1")
f.X25519(testkit.TestX25519Recipient)
f.HMAC()
f.Payload("age")
file := f.Bytes()
f.Buf.Reset()
f.TextLine("----- BEGIN AGE ENCRYPTED FILE -----")
f.Body(file)
f.Base64Padding()
f.EndArmor("AGE ENCRYPTED FILE")
f.ExpectArmorFailure()
f.Generate()
}

View file

@ -0,0 +1,26 @@
// Copyright 2022 The age Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build ignore
// +build ignore
package main
import "filippo.io/age/internal/testkit"
func main() {
f := testkit.NewTestFile()
f.VersionLine("v1")
f.X25519(testkit.TestX25519Recipient)
f.HMAC()
f.Payload("age")
file := f.Bytes()
f.Buf.Reset()
f.BeginArmor("AGE ENCRYPTED FILE")
f.Body(file)
f.Base64Padding()
f.TextLine("----- END AGE ENCRYPTED FILE -----")
f.ExpectArmorFailure()
f.Generate()
}

View file

@ -0,0 +1,29 @@
// Copyright 2022 The age Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build ignore
// +build ignore
package main
import "filippo.io/age/internal/testkit"
func main() {
f := testkit.NewTestFile()
f.VersionLine("v1")
f.X25519(testkit.TestX25519Recipient)
f.HMAC()
f.Payload("age")
file := f.Bytes()
f.Buf.Reset()
f.BeginArmor("AGE ENCRYPTED FILE")
f.Body(file)
f.Base64Padding()
line2, line1 := f.UnreadLine(), f.UnreadLine()
f.TextLine(line1 + " ")
f.TextLine(line2)
f.EndArmor("AGE ENCRYPTED FILE")
f.ExpectArmorFailure()
f.Generate()
}

View file

@ -0,0 +1,27 @@
// Copyright 2022 The age Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build ignore
// +build ignore
package main
import "filippo.io/age/internal/testkit"
func main() {
f := testkit.NewTestFile()
f.VersionLine("v1")
f.X25519(testkit.TestX25519Recipient)
f.HMAC()
f.Payload("age")
file := f.Bytes()
f.Buf.Reset()
f.BeginArmor("AGE ENCRYPTED FILE")
f.Body(file)
f.Base64Padding()
f.TextLine(f.UnreadLine() + " ")
f.EndArmor("AGE ENCRYPTED FILE")
f.ExpectArmorFailure()
f.Generate()
}

View file

@ -0,0 +1,29 @@
// Copyright 2022 The age Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build ignore
// +build ignore
package main
import "filippo.io/age/internal/testkit"
func main() {
f := testkit.NewTestFile()
f.VersionLine("v1")
f.X25519(testkit.TestX25519Recipient)
f.HMAC()
f.Payload("age")
file := f.Bytes()
f.Buf.Reset()
f.BeginArmor("AGE ENCRYPTED FILE")
f.Body(file)
f.Base64Padding()
line2, line1 := f.UnreadLine(), f.UnreadLine()
f.TextLine(" " + line1)
f.TextLine(line2)
f.EndArmor("AGE ENCRYPTED FILE")
f.ExpectArmorFailure()
f.Generate()
}

View file

@ -0,0 +1,28 @@
// Copyright 2022 The age Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build ignore
// +build ignore
package main
import "filippo.io/age/internal/testkit"
func main() {
f := testkit.NewTestFile()
f.VersionLine("v1")
f.X25519(testkit.TestX25519Recipient)
f.HMAC()
f.Payload("age")
file := f.Bytes()
f.Buf.Reset()
f.Buf.Write([]byte("\n\r \t\n"))
f.BeginArmor("AGE ENCRYPTED FILE")
f.Body(file)
f.Base64Padding()
f.EndArmor("AGE ENCRYPTED FILE")
f.Buf.Write([]byte("\n\r \t\n"))
f.Comment("whitespace is allowed before and after armored files")
f.Generate()
}

26
tests/armor_wrong_type.go Normal file
View file

@ -0,0 +1,26 @@
// Copyright 2022 The age Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build ignore
// +build ignore
package main
import "filippo.io/age/internal/testkit"
func main() {
f := testkit.NewTestFile()
f.VersionLine("v1")
f.X25519(testkit.TestX25519Recipient)
f.HMAC()
f.Payload("age")
file := f.Bytes()
f.Buf.Reset()
f.BeginArmor("AGE ENCRYPTED MESSAGE")
f.Body(file)
f.Base64Padding()
f.EndArmor("AGE ENCRYPTED MESSAGE")
f.ExpectArmorFailure()
f.Generate()
}