| 109 | } |
| 110 | |
| 111 | func TestEncryptDecrypt(t *testing.T) { |
| 112 | var password = "CovenantSQL.io" |
| 113 | Convey("encrypt & decrypt 0 length string with aes128", t, func() { |
| 114 | enc, err := Encrypt([]byte(""), []byte(password)) |
| 115 | So(enc, ShouldNotBeNil) |
| 116 | So(len(enc), ShouldEqual, 2*aes.BlockSize) |
| 117 | So(err, ShouldBeNil) |
| 118 | |
| 119 | dec, err := Decrypt(enc, []byte(password)) |
| 120 | So(dec, ShouldNotBeNil) |
| 121 | So(len(dec), ShouldEqual, 0) |
| 122 | So(err, ShouldBeNil) |
| 123 | }) |
| 124 | |
| 125 | Convey("encrypt & decrypt 0 length bytes with aes128", t, func() { |
| 126 | enc, err := Encrypt([]byte(nil), []byte(password)) |
| 127 | So(enc, ShouldNotBeNil) |
| 128 | So(len(enc), ShouldEqual, 2*aes.BlockSize) |
| 129 | So(err, ShouldBeNil) |
| 130 | |
| 131 | dec, err := Decrypt(enc, []byte(password)) |
| 132 | So(dec, ShouldNotBeNil) |
| 133 | So(len(dec), ShouldEqual, 0) |
| 134 | So(err, ShouldBeNil) |
| 135 | }) |
| 136 | |
| 137 | Convey("encrypt & decrypt 1 byte with aes128", t, func() { |
| 138 | enc, err := Encrypt([]byte{0x11}, []byte(password)) |
| 139 | So(enc, ShouldNotBeNil) |
| 140 | So(len(enc), ShouldEqual, 2*aes.BlockSize) |
| 141 | So(err, ShouldBeNil) |
| 142 | |
| 143 | dec, err := Decrypt(enc, []byte(password)) |
| 144 | So(dec, ShouldResemble, []byte{0x11}) |
| 145 | So(len(dec), ShouldEqual, 1) |
| 146 | So(err, ShouldBeNil) |
| 147 | }) |
| 148 | |
| 149 | Convey("encrypt & decrypt 1747 length bytes", t, func() { |
| 150 | in := bytes.Repeat([]byte{0xff}, 1747) |
| 151 | enc, err := Encrypt(in, []byte(password)) |
| 152 | So(enc, ShouldNotBeNil) |
| 153 | So(len(enc), ShouldEqual, (1747/aes.BlockSize+2)*aes.BlockSize) |
| 154 | So(err, ShouldBeNil) |
| 155 | |
| 156 | dec, err := Decrypt(enc, []byte(password)) |
| 157 | So(dec, ShouldResemble, in) |
| 158 | So(len(dec), ShouldEqual, 1747) |
| 159 | So(err, ShouldBeNil) |
| 160 | }) |
| 161 | |
| 162 | Convey("encrypt & decrypt 32 length bytes", t, func() { |
| 163 | in := bytes.Repeat([]byte{0xcc}, 32) |
| 164 | enc, err := Encrypt(in, []byte(password)) |
| 165 | So(enc, ShouldNotBeNil) |
| 166 | So(len(enc), ShouldEqual, (32/aes.BlockSize+2)*aes.BlockSize) |
| 167 | So(err, ShouldBeNil) |
| 168 | |