Search in sources :

Example 1 with SignResponse

use of com.microsoft.azure.sdk.iot.device.hsm.parser.SignResponse in project azure-iot-sdk-java by Azure.

the class SignResponseTest method getDigestWorks.

// Tests_SRS_HTTPHSMSIGNRESPONSE_34_001: [This function shall return the saved digest.]
@Test
public void getDigestWorks() {
    // arrange
    String expectedDigest = "some digest";
    SignResponse response = new SignResponse();
    Deencapsulation.setField(response, "digest", expectedDigest);
    // act
    String actualDigest = response.getDigest();
    // assert
    assertEquals(expectedDigest, actualDigest);
}
Also used : SignResponse(com.microsoft.azure.sdk.iot.device.hsm.parser.SignResponse) Test(org.junit.Test)

Example 2 with SignResponse

use of com.microsoft.azure.sdk.iot.device.hsm.parser.SignResponse in project azure-iot-sdk-java by Azure.

the class HttpHsmSignatureProvider method sign.

/**
 * Sign the provided data using the provided key name
 * @param keyName the key used for signing
 * @param data the data to be signed
 * @param generationId the generation id
 * @return the signed data
 * @throws IOException If the http client cannot reach the signing party
 * @throws TransportException If the http client cannot reach the signing party
 * @throws URISyntaxException If the url for the signing party cannot be parsed
 */
public String sign(String keyName, String data, String generationId) throws IOException, TransportException, URISyntaxException, HsmException {
    if (data == null || data.isEmpty()) {
        // Codes_SRS_HTTPHSMSIGNATUREPROVIDER_34_007: [If the provided data is null or empty, this function shall throw an IllegalArgumentException.]
        throw new IllegalArgumentException("Data cannot be null or empty");
    }
    // Codes_SRS_HTTPHSMSIGNATUREPROVIDER_34_006: [This function shall create a signRequest for the hsm http client to sign, and shall return the utf-8 encoded result of that signing.]
    SignRequest signRequest = new SignRequest();
    signRequest.setAlgo(defaultSignRequestAlgo);
    signRequest.setData(data.getBytes(ENCODING_CHARSET));
    signRequest.setKeyId(DEFAULT_KEY_ID);
    SignResponse response = this.httpClient.sign(this.apiVersion, keyName, signRequest, generationId);
    return URLEncoder.encode(response.getDigest(), ENCODING_CHARSET);
}
Also used : SignRequest(com.microsoft.azure.sdk.iot.device.hsm.parser.SignRequest) SignResponse(com.microsoft.azure.sdk.iot.device.hsm.parser.SignResponse)

Aggregations

SignResponse (com.microsoft.azure.sdk.iot.device.hsm.parser.SignResponse)2 SignRequest (com.microsoft.azure.sdk.iot.device.hsm.parser.SignRequest)1 Test (org.junit.Test)1