// Path: src/test/java/org/unitedid/yhsm/SetupCommon.java
// public class SetupCommon {
//     public YubiHSM hsm;
//     public DeviceHandler deviceHandler;
//     public int keyHandle = 8192;
//     public final String configPassPhrase = "";
//     public final String hsmPassPhrase = "badabada";
//     public final String adminYubikey = "ftftftfteeee";
// 
// 
//     @BeforeTest
//     public void setUp() throws Exception {
//         String deviceName = "/dev/ttyACM0";
//         if (System.getProperty("hsm.test.deviceName") != null) {
//             deviceName = System.getProperty("hsm.test.deviceName");
//         }
//         hsm = new YubiHSM(deviceName);
//         deviceHandler = hsm.getRawDevice();
//     }
// 
//     @AfterTest
//     public void tearDown() throws Exception {
//         hsm = null;
//         deviceHandler = null;
//     }
// 
// }
// 
// Path: src/main/java/org/unitedid/yhsm/internal/Defines.java
// final static public byte YSM_HMAC_SHA1_FINAL = 0x02;
// 
// Path: src/main/java/org/unitedid/yhsm/internal/Defines.java
// final static public byte YSM_HMAC_SHA1_RESET = 0x01;
// 
// Path: src/main/java/org/unitedid/yhsm/internal/Defines.java
// final static public int YSM_SHA1_HASH_SIZE = 20;


import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
import org.unitedid.yhsm.SetupCommon;
import java.util.Map;
import static org.testng.Assert.assertEquals;
import static org.unitedid.yhsm.internal.Defines.YSM_HMAC_SHA1_FINAL;
import static org.unitedid.yhsm.internal.Defines.YSM_HMAC_SHA1_RESET;
import static org.unitedid.yhsm.internal.Defines.YSM_SHA1_HASH_SIZE;

    @Test
    public void testHMACSHA1NextNext() throws Exception {
        Map<String, String> result = hsm.generateHMACSHA1("", keyHandle, false, false);
        assertEquals(result.get("hash"), expectedNextHash);
        result = hsm.generateHMACSHA1Next(data.substring(0, 3), keyHandle, false, false);
        assertEquals(result.get("hash"), expectedNextHash);
        result = hsm.generateHMACSHA1Next(data.substring(3), keyHandle, true, false);
        assertEquals(result.get("hash"), expectedHash);
    }

    @Test
    public void testHMACSHA1Interupted() throws Exception {
        Map<String, String> result = hsm.generateHMACSHA1(data.substring(0, 3), keyHandle, false, false);
        assertEquals(result.get("hash"), expectedNextHash);
        assertEquals(hsm.echo("123qwe"), "123qwe");
        result = hsm.generateHMACSHA1Next(data.substring(3), keyHandle, true, false);
        assertEquals(result.get("hash"), expectedHash);
    }

    @Test(expectedExceptions = YubiHSMCommandFailedException.class,
          expectedExceptionsMessageRegExp = "Command YSM_HMAC_SHA1_GENERATE failed: YSM_FUNCTION_DISABLED")
    public void testHMACSHA1InvalidKeyHandle() throws Exception {
        hsm.generateHMACSHA1(data, 1, true, false);
    }

    @Test
    public void testHMACSHA1ToBuffer() throws Exception {
        assertEquals(hsm.loadRandomBufferData(0, 0), 0);
        hsm.generateHMACSHA1(data, keyHandle, true, true);
// Path: src/test/java/org/unitedid/yhsm/SetupCommon.java
// public class SetupCommon {
//     public YubiHSM hsm;
//     public DeviceHandler deviceHandler;
//     public int keyHandle = 8192;
//     public final String configPassPhrase = "";
//     public final String hsmPassPhrase = "badabada";
//     public final String adminYubikey = "ftftftfteeee";
// 
// 
//     @BeforeTest
//     public void setUp() throws Exception {
//         String deviceName = "/dev/ttyACM0";
//         if (System.getProperty("hsm.test.deviceName") != null) {
//             deviceName = System.getProperty("hsm.test.deviceName");
//         }
//         hsm = new YubiHSM(deviceName);
//         deviceHandler = hsm.getRawDevice();
//     }
// 
//     @AfterTest
//     public void tearDown() throws Exception {
//         hsm = null;
//         deviceHandler = null;
//     }
// 
// }
// 
// Path: src/main/java/org/unitedid/yhsm/internal/Defines.java
// final static public byte YSM_HMAC_SHA1_FINAL = 0x02;
// 
// Path: src/main/java/org/unitedid/yhsm/internal/Defines.java
// final static public byte YSM_HMAC_SHA1_RESET = 0x01;
// 
// Path: src/main/java/org/unitedid/yhsm/internal/Defines.java
// final static public int YSM_SHA1_HASH_SIZE = 20;


// Path: src/test/java/org/unitedid/yhsm/internal/HMACCmdTest.java
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
import org.unitedid.yhsm.SetupCommon;
import java.util.Map;
import static org.testng.Assert.assertEquals;
import static org.unitedid.yhsm.internal.Defines.YSM_HMAC_SHA1_FINAL;
import static org.unitedid.yhsm.internal.Defines.YSM_HMAC_SHA1_RESET;
import static org.unitedid.yhsm.internal.Defines.YSM_SHA1_HASH_SIZE;


    @Test
    public void testHMACSHA1NextNext() throws Exception {
        Map<String, String> result = hsm.generateHMACSHA1("", keyHandle, false, false);
        assertEquals(result.get("hash"), expectedNextHash);
        result = hsm.generateHMACSHA1Next(data.substring(0, 3), keyHandle, false, false);
        assertEquals(result.get("hash"), expectedNextHash);
        result = hsm.generateHMACSHA1Next(data.substring(3), keyHandle, true, false);
        assertEquals(result.get("hash"), expectedHash);
    }

    @Test
    public void testHMACSHA1Interupted() throws Exception {
        Map<String, String> result = hsm.generateHMACSHA1(data.substring(0, 3), keyHandle, false, false);
        assertEquals(result.get("hash"), expectedNextHash);
        assertEquals(hsm.echo("123qwe"), "123qwe");
        result = hsm.generateHMACSHA1Next(data.substring(3), keyHandle, true, false);
        assertEquals(result.get("hash"), expectedHash);
    }

    @Test(expectedExceptions = YubiHSMCommandFailedException.class,
          expectedExceptionsMessageRegExp = "Command YSM_HMAC_SHA1_GENERATE failed: YSM_FUNCTION_DISABLED")
    public void testHMACSHA1InvalidKeyHandle() throws Exception {
        hsm.generateHMACSHA1(data, 1, true, false);
    }

    @Test
    public void testHMACSHA1ToBuffer() throws Exception {
        assertEquals(hsm.loadRandomBufferData(0, 0), 0);
        hsm.generateHMACSHA1(data, keyHandle, true, true);
        assertEquals(hsm.loadRandomBufferData(0, 1), YSM_SHA1_HASH_SIZE);