mirror of
https://github.com/FiloSottile/age.git
synced 2026-01-10 13:47:20 +00:00
testdata: convert last chunk tests to testkit
This commit is contained in:
@@ -130,8 +130,7 @@ func (f *TestFile) HMAC() {
|
||||
f.HMACLine(h.Sum(nil))
|
||||
}
|
||||
|
||||
func (f *TestFile) Nonce() {
|
||||
nonce := f.Rand(16)
|
||||
func (f *TestFile) Nonce(nonce []byte) {
|
||||
f.streamKey = make([]byte, 32)
|
||||
hkdf.New(sha256.New, f.fileKey, nonce, []byte("payload")).Read(f.streamKey)
|
||||
f.Buf.Write(nonce)
|
||||
@@ -152,7 +151,7 @@ func (f *TestFile) PayloadChunkFinal(plaintext []byte) {
|
||||
}
|
||||
|
||||
func (f *TestFile) Payload(plaintext string) {
|
||||
f.Nonce()
|
||||
f.Nonce(f.Rand(16))
|
||||
f.PayloadChunkFinal([]byte(plaintext))
|
||||
}
|
||||
|
||||
|
||||
32
testdata/stream_last_chunk_empty.go
vendored
Normal file
32
testdata/stream_last_chunk_empty.go
vendored
Normal file
@@ -0,0 +1,32 @@
|
||||
// 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
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/hex"
|
||||
|
||||
"filippo.io/age/internal/testkit"
|
||||
)
|
||||
|
||||
func main() {
|
||||
f := testkit.NewTestFile()
|
||||
// Reuse the file key and nonce from a previous test vector to avoid
|
||||
// bloating the git history with two versions that can't be compressed.
|
||||
fileKey, _ := hex.DecodeString("7aa5bdac0e6afeed3dd0a7eccb42af44")
|
||||
f.FileKey(fileKey)
|
||||
f.VersionLine("v1")
|
||||
f.X25519(testkit.TestX25519Identity)
|
||||
f.HMAC()
|
||||
nonce, _ := hex.DecodeString("c82f71eb82029b77136399e485e879f4")
|
||||
f.Nonce(nonce)
|
||||
f.PayloadChunk(bytes.Repeat([]byte{0}, 64*1024))
|
||||
f.PayloadChunkFinal([]byte{})
|
||||
f.Comment("final STREAM chunk can't be empty unless whole payload is empty")
|
||||
f.ExpectPayloadFailure()
|
||||
f.Generate()
|
||||
}
|
||||
Binary file not shown.
29
testdata/stream_last_chunk_full.go
vendored
Normal file
29
testdata/stream_last_chunk_full.go
vendored
Normal 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
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/hex"
|
||||
|
||||
"filippo.io/age/internal/testkit"
|
||||
)
|
||||
|
||||
func main() {
|
||||
f := testkit.NewTestFile()
|
||||
// Reuse the file key and nonce from a previous test vector to avoid
|
||||
// bloating the git history with two versions that can't be compressed.
|
||||
fileKey, _ := hex.DecodeString("5085919e0d59b19d6cbd00330f03861c")
|
||||
f.FileKey(fileKey)
|
||||
f.VersionLine("v1")
|
||||
f.X25519(testkit.TestX25519Identity)
|
||||
f.HMAC()
|
||||
nonce, _ := hex.DecodeString("32521791a6f22e11637fb69ead3f2d5f")
|
||||
f.Nonce(nonce)
|
||||
f.PayloadChunkFinal(bytes.Repeat([]byte{0}, 64*1024))
|
||||
f.Generate()
|
||||
}
|
||||
Binary file not shown.
Reference in New Issue
Block a user