mac_test.go 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. // Copyright 2015 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 pkcs12
  5. import (
  6. "encoding/asn1"
  7. "testing"
  8. )
  9. func TestVerifyMac(t *testing.T) {
  10. td := macData{
  11. Mac: digestInfo{
  12. Digest: []byte{0x18, 0x20, 0x3d, 0xff, 0x1e, 0x16, 0xf4, 0x92, 0xf2, 0xaf, 0xc8, 0x91, 0xa9, 0xba, 0xd6, 0xca, 0x9d, 0xee, 0x51, 0x93},
  13. },
  14. MacSalt: []byte{1, 2, 3, 4, 5, 6, 7, 8},
  15. Iterations: 2048,
  16. }
  17. message := []byte{11, 12, 13, 14, 15}
  18. password, _ := bmpString("")
  19. td.Mac.Algorithm.Algorithm = asn1.ObjectIdentifier([]int{1, 2, 3})
  20. err := verifyMac(&td, message, password)
  21. if _, ok := err.(NotImplementedError); !ok {
  22. t.Errorf("err: %v", err)
  23. }
  24. td.Mac.Algorithm.Algorithm = asn1.ObjectIdentifier([]int{1, 3, 14, 3, 2, 26})
  25. err = verifyMac(&td, message, password)
  26. if err != ErrIncorrectPassword {
  27. t.Errorf("Expected incorrect password, got err: %v", err)
  28. }
  29. password, _ = bmpString("Sesame open")
  30. err = verifyMac(&td, message, password)
  31. if err != nil {
  32. t.Errorf("err: %v", err)
  33. }
  34. }