Skip to content

Commit

Permalink
remove PngNoMaxSizeFunc, update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
James-Pickett committed Apr 16, 2024
1 parent a324923 commit 013d665
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 20 deletions.
14 changes: 4 additions & 10 deletions cross_language_tests/boxer_cross_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -345,20 +345,14 @@ func TestBoxerMaxSize(t *testing.T) {
t.Parallel()
dir := t.TempDir()

responseTo := ulid.New()
ciphertext, err := aliceBoxer.Encode(responseTo, tooBigBytes)
require.NoError(t, err)

var png bytes.Buffer
pngFile := path.Join(dir, ulid.New()+".png")
require.NoError(t, krypto.ToPngNoMaxSize(&png, tooBigBytes))
//#nosec G306 -- Need readable files
require.NoError(t, os.WriteFile(pngFile, png.Bytes(), 0644))
require.NoError(t, os.WriteFile(pngFile, []byte(tooBigBytesB64), 0644))

tests := []boxerCrossTestCase{
{Key: bobPem.Bytes(), Counterparty: alicePubPem.Bytes(), Ciphertext: ciphertext, cmd: "decode"},
{Key: bobPem.Bytes(), Counterparty: alicePubPem.Bytes(), Ciphertext: ciphertext, cmd: "decodeunverified"},
{Key: bobPem.Bytes(), Ciphertext: ciphertext, cmd: "decodeunverified"},
{Key: bobPem.Bytes(), Counterparty: alicePubPem.Bytes(), Ciphertext: tooBigBytesB64, cmd: "decode"},
{Key: bobPem.Bytes(), Counterparty: alicePubPem.Bytes(), Ciphertext: tooBigBytesB64, cmd: "decodeunverified"},
{Key: bobPem.Bytes(), Ciphertext: tooBigBytesB64, cmd: "decodeunverified"},
{Key: bobPem.Bytes(), Counterparty: alicePubPem.Bytes(), PngFile: pngFile, cmd: "decodepng"},
}

Expand Down
16 changes: 6 additions & 10 deletions png.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,12 @@ const (
V0MaxSize = 4 * 1024 * 1024
)

func ToPngNoMaxSize(w io.Writer, data []byte) error {
func ToPng(w io.Writer, data []byte) error {
dataSize := len(data)
if dataSize > V0MaxSize {
return fmt.Errorf("data too big: %d is bigger than %d", dataSize, V0MaxSize)
}

pixelCount := divCeil(len(data), usableBytesPerPixel)
pixelCount = pixelCount + pixelsInHeader + 1

Expand Down Expand Up @@ -60,15 +65,6 @@ func ToPngNoMaxSize(w io.Writer, data []byte) error {
return encoder.Encode(w, img)
}

func ToPng(w io.Writer, data []byte) error {
dataSize := len(data)
if dataSize > V0MaxSize {
return fmt.Errorf("data too big: %d is bigger than %d", dataSize, V0MaxSize)
}

return ToPngNoMaxSize(w, data)
}

func FromPng(r io.Reader, w io.Writer) error {
imgRaw, _, err := image.Decode(r)
if err != nil {
Expand Down

0 comments on commit 013d665

Please sign in to comment.