...

Source file src/golang.org/x/crypto/openpgp/packet/compressed_test.go

Documentation: golang.org/x/crypto/openpgp/packet

     1  // Copyright 2011 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package packet
     6  
     7  import (
     8  	"bytes"
     9  	"encoding/hex"
    10  	"io"
    11  	"testing"
    12  )
    13  
    14  func TestCompressed(t *testing.T) {
    15  	packet, err := Read(readerFromHex(compressedHex))
    16  	if err != nil {
    17  		t.Errorf("failed to read Compressed: %s", err)
    18  		return
    19  	}
    20  
    21  	c, ok := packet.(*Compressed)
    22  	if !ok {
    23  		t.Error("didn't find Compressed packet")
    24  		return
    25  	}
    26  
    27  	contents, err := io.ReadAll(c.Body)
    28  	if err != nil && err != io.EOF {
    29  		t.Error(err)
    30  		return
    31  	}
    32  
    33  	expected, _ := hex.DecodeString(compressedExpectedHex)
    34  	if !bytes.Equal(expected, contents) {
    35  		t.Errorf("got:%x want:%x", contents, expected)
    36  	}
    37  }
    38  
    39  const compressedHex = "a3013b2d90c4e02b72e25f727e5e496a5e49b11e1700"
    40  const compressedExpectedHex = "cb1062004d14c8fe636f6e74656e74732e0a"
    41  

View as plain text