signature_test.go 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  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. package packet
  5. import (
  6. "bytes"
  7. "crypto"
  8. "encoding/hex"
  9. "testing"
  10. )
  11. func TestSignatureRead(t *testing.T) {
  12. packet, err := Read(readerFromHex(signatureDataHex))
  13. if err != nil {
  14. t.Error(err)
  15. return
  16. }
  17. sig, ok := packet.(*Signature)
  18. if !ok || sig.SigType != SigTypeBinary || sig.PubKeyAlgo != PubKeyAlgoRSA || sig.Hash != crypto.SHA1 {
  19. t.Errorf("failed to parse, got: %#v", packet)
  20. }
  21. }
  22. func TestSignatureReserialize(t *testing.T) {
  23. packet, _ := Read(readerFromHex(signatureDataHex))
  24. sig := packet.(*Signature)
  25. out := new(bytes.Buffer)
  26. err := sig.Serialize(out)
  27. if err != nil {
  28. t.Errorf("error reserializing: %s", err)
  29. return
  30. }
  31. expected, _ := hex.DecodeString(signatureDataHex)
  32. if !bytes.Equal(expected, out.Bytes()) {
  33. t.Errorf("output doesn't match input (got vs expected):\n%s\n%s", hex.Dump(out.Bytes()), hex.Dump(expected))
  34. }
  35. }
  36. const signatureDataHex = "c2c05c04000102000605024cb45112000a0910ab105c91af38fb158f8d07ff5596ea368c5efe015bed6e78348c0f033c931d5f2ce5db54ce7f2a7e4b4ad64db758d65a7a71773edeab7ba2a9e0908e6a94a1175edd86c1d843279f045b021a6971a72702fcbd650efc393c5474d5b59a15f96d2eaad4c4c426797e0dcca2803ef41c6ff234d403eec38f31d610c344c06f2401c262f0993b2e66cad8a81ebc4322c723e0d4ba09fe917e8777658307ad8329adacba821420741009dfe87f007759f0982275d028a392c6ed983a0d846f890b36148c7358bdb8a516007fac760261ecd06076813831a36d0459075d1befa245ae7f7fb103d92ca759e9498fe60ef8078a39a3beda510deea251ea9f0a7f0df6ef42060f20780360686f3e400e"