You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

53 rivejä
1.3 KiB

  1. // Copyright 2010 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 tls
  5. import (
  6. "testing"
  7. )
  8. func TestRoundUp(t *testing.T) {
  9. if roundUp(0, 16) != 0 ||
  10. roundUp(1, 16) != 16 ||
  11. roundUp(15, 16) != 16 ||
  12. roundUp(16, 16) != 16 ||
  13. roundUp(17, 16) != 32 {
  14. t.Error("roundUp broken")
  15. }
  16. }
  17. var paddingTests = []struct {
  18. in []byte
  19. good bool
  20. expectedLen int
  21. }{
  22. {[]byte{1, 2, 3, 4, 0}, true, 4},
  23. {[]byte{1, 2, 3, 4, 0, 1}, false, 0},
  24. {[]byte{1, 2, 3, 4, 99, 99}, false, 0},
  25. {[]byte{1, 2, 3, 4, 1, 1}, true, 4},
  26. {[]byte{1, 2, 3, 2, 2, 2}, true, 3},
  27. {[]byte{1, 2, 3, 3, 3, 3}, true, 2},
  28. {[]byte{1, 2, 3, 4, 3, 3}, false, 0},
  29. {[]byte{1, 4, 4, 4, 4, 4}, true, 1},
  30. {[]byte{5, 5, 5, 5, 5, 5}, true, 0},
  31. {[]byte{6, 6, 6, 6, 6, 6}, false, 0},
  32. }
  33. func TestRemovePadding(t *testing.T) {
  34. for i, test := range paddingTests {
  35. payload, good := removePadding(test.in)
  36. expectedGood := byte(255)
  37. if !test.good {
  38. expectedGood = 0
  39. }
  40. if good != expectedGood {
  41. t.Errorf("#%d: wrong validity, want:%d got:%d", i, expectedGood, good)
  42. }
  43. if good == 255 && len(payload) != test.expectedLen {
  44. t.Errorf("#%d: got %d, want %d", i, len(payload), test.expectedLen)
  45. }
  46. }
  47. }