github.com/Ptt-official-app/go-bbs@v0.12.0/crypt/bbscrypt_test.go (about) 1 package crypt 2 3 import ( 4 "reflect" 5 "testing" 6 ) 7 8 func TestFcrypt(t *testing.T) { 9 type args struct { 10 key []byte 11 salt []byte 12 } 13 tests := []struct { 14 name string 15 args args 16 expected []byte 17 wantErr bool 18 }{ 19 // TODO: Add test cases. 20 { 21 args: args{ 22 key: []byte("012345678901"), 23 salt: []byte("AA3QBhLWk1BWA"), 24 }, 25 expected: []byte("AA3QBhLWk1BWA\x00"), 26 }, 27 { 28 args: args{ 29 key: []byte("012345678901"), 30 salt: []byte("A?3QBhLWk1BWA"), 31 }, 32 expected: []byte("A?A48O5srqPSU\x00"), 33 }, 34 { 35 args: args{ 36 key: []byte("ABCD45678901"), 37 salt: []byte("AA9VbueZXojAA"), 38 }, 39 expected: []byte("AA9VbueZXojAA\x00"), 40 }, 41 { 42 name: "key: 8 0's, salt: 9 0's", 43 args: args{ 44 key: []byte("00000000"), 45 salt: []byte("000000000"), 46 }, 47 expected: []byte("00CfV146ZJdLc\x00"), 48 }, 49 { 50 args: args{ 51 key: []byte("000000001123123123"), 52 salt: []byte("000000000"), 53 }, 54 expected: []byte("00CfV146ZJdLc\x00"), 55 }, 56 { 57 args: args{ 58 key: []byte("00000000112312sdfasdf3123"), 59 salt: []byte("000010011asfasdfsaf"), 60 }, 61 expected: []byte("00CfV146ZJdLc\x00"), 62 }, 63 { 64 args: args{ 65 key: []byte("00000000112312sdfasdf3123"), 66 salt: []byte("021010011asfasdfsaf"), 67 }, 68 expected: []byte("02v6ADqeCsb12\x00"), 69 }, 70 { 71 args: args{ 72 key: []byte("123123"), 73 salt: []byte("bhwvOJtfT1TAI"), 74 }, 75 expected: []byte("bhwvOJtfT1TAI\x00"), 76 }, 77 } 78 79 gots := make([][]byte, len(tests)) 80 for idx, tt := range tests { 81 t.Run(tt.name, func(t *testing.T) { 82 got, err := Fcrypt(tt.args.key, tt.args.salt) 83 if (err != nil) != tt.wantErr { 84 t.Errorf("Fcrypt() error = %v, wantErr %v", err, tt.wantErr) 85 return 86 } 87 if !reflect.DeepEqual(got, tt.expected) { 88 t.Errorf("Fcrypt() = %v, expected %v", got, tt.expected) 89 } 90 gots[idx] = got 91 }) 92 } 93 }