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);
}
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);
}
Aggregations