2 * Copyright (c) 2010-2023 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
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
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.binding.tplinksmarthome.internal;
15 import static org.junit.jupiter.api.Assertions.assertEquals;
17 import java.io.ByteArrayInputStream;
18 import java.io.IOException;
20 import org.junit.jupiter.api.Test;
23 * Test class for {@link CryptUtil} class.
25 * @author Hilbrand Bouwkamp - Initial contribution
27 public class CryptUtilTest {
29 private static final String TEST_STRING = "This is just a message";
32 * Test round trip of encrypt and decrypt that should return the same value.
34 * @throws IOException exception in case device not reachable
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");
43 * Test round trip of encrypt and decrypt with length that should return the same value.
45 * @throws IOException exception in case device not reachable
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");