]> git.basschouten.com Git - openhab-addons.git/blob
f5932efb1630361a7f892eccaa50b4a35361f7f4
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2023 Contributors to the openHAB project
3  *
4  * See the NOTICE file(s) distributed with this work for additional
5  * information.
6  *
7  * This program and the accompanying materials are made available under the
8  * terms of the Eclipse Public License 2.0 which is available at
9  * http://www.eclipse.org/legal/epl-2.0
10  *
11  * SPDX-License-Identifier: EPL-2.0
12  */
13 package org.openhab.binding.tplinksmarthome.internal;
14
15 import static org.junit.jupiter.api.Assertions.assertEquals;
16
17 import java.io.ByteArrayInputStream;
18 import java.io.IOException;
19
20 import org.junit.jupiter.api.Test;
21
22 /**
23  * Test class for {@link CryptUtil} class.
24  *
25  * @author Hilbrand Bouwkamp - Initial contribution
26  */
27 public class CryptUtilTest {
28
29     private static final String TEST_STRING = "This is just a message";
30
31     /**
32      * Test round trip of encrypt and decrypt that should return the same value.
33      *
34      * @throws IOException exception in case device not reachable
35      */
36     @Test
37     public void testCrypt() throws IOException {
38         assertEquals(TEST_STRING, CryptUtil.decrypt(CryptUtil.encrypt(TEST_STRING), TEST_STRING.length()),
39                 "Crypting should result in same string");
40     }
41
42     /**
43      * Test round trip of encrypt and decrypt with length that should return the same value.
44      *
45      * @throws IOException exception in case device not reachable
46      */
47     @Test
48     public void testCryptWithLength() throws IOException {
49         try (final ByteArrayInputStream is = new ByteArrayInputStream(CryptUtil.encryptWithLength(TEST_STRING))) {
50             assertEquals(TEST_STRING, CryptUtil.decryptWithLength(is), "Crypting should result in same string");
51         }
52     }
53 }