github.com/signintech/pdft@v0.5.0/minigopdf/pdf_protection_test.go (about) 1 package gopdf 2 3 import "testing" 4 5 func TestSetProtection(t *testing.T) { 6 7 var pp PDFProtection 8 pp.setProtection(PermissionsPrint|PermissionsCopy|PermissionsModify, []byte("5555"), []byte("1234")) 9 var realOValue = []byte{ 10 0xbb, 0xb8, 0x04, 0x6d, 0x96, 0xa9, 0x9a, 0x23, 0x46, 0xa9, 0x41, 0x21, 0x06, 0x8c, 0xad, 0x4f, 0x83, 0x5e, 0x5d, 0x0e, 0xcb, 0xb6, 0x20, 0xa8, 0xb7, 0xa3, 0x16, 0x13, 0x3c, 0x8f, 0x02, 0x91, 11 } 12 13 var realUValue = []byte{ 14 0x19, 0x27, 0x67, 0x2a, 0x4f, 0x28, 0x64, 0xb3, 0x8b, 0x8b, 0x40, 0x44, 0x2, 0xa2, 0x68, 0x72, 0x2f, 0xe1, 0xb9, 0xf8, 0x4, 0x24, 0x81, 0xe, 0xe8, 0x84, 0xd8, 0x30, 0xd5, 0xe9, 0x8f, 0x24, 15 } 16 17 if !isSliceEq(pp.oValue, realOValue) { 18 t.Errorf("wrong oValue") 19 return 20 } 21 22 if !isSliceEq(pp.uValue, realUValue) { 23 t.Errorf("wrong oValue") 24 return 25 } 26 27 if pp.pValue != -36 { 28 t.Errorf("wrong pValue") 29 return 30 } 31 32 var realObjKey4 = []byte{ 33 0xb3, 0x9, 0xe6, 0x55, 0xd8, 0x23, 0xbf, 0xbb, 0xc5, 0xdf, 34 } 35 if !isSliceEq(pp.objectkey(4), realObjKey4) { 36 t.Errorf("wrong objectkey 4") 37 return 38 } 39 40 var realObjKey5 = []byte{ 41 0xc4, 0x2c, 0x3e, 0x35, 0x92, 0xbe, 0x5e, 0x25, 0xdd, 0x1b, 42 } 43 if !isSliceEq(pp.objectkey(5), realObjKey5) { 44 t.Errorf("wrong objectkey 5") 45 return 46 } 47 } 48 49 func isSliceEq(a, b []byte) bool { 50 51 if a == nil && b == nil { 52 return true 53 } 54 55 if a == nil || b == nil { 56 return false 57 } 58 59 if len(a) != len(b) { 60 return false 61 } 62 63 for i := range a { 64 if a[i] != b[i] { 65 return false 66 } 67 } 68 69 return true 70 }