Search in sources :

Example 1 with SymmetricKeyParser

use of com.microsoft.azure.sdk.iot.deps.serializer.SymmetricKeyParser in project azure-iot-sdk-java by Azure.

the class SymmetricKeyParserTest method testGettersAndSetters.

// Tests_SRS_SymmetricKeyParser_34_001: [This method shall return the value of primaryKey]
// Tests_SRS_SymmetricKeyParser_34_003: [This method shall set the value of primaryKey to the provided value.]
// Tests_SRS_SymmetricKeyParser_34_004: [This method shall return the value of secondaryKey]
// Tests_SRS_SymmetricKeyParser_34_006: [This method shall set the value of secondaryKey to the provided value.]
@Test
public void testGettersAndSetters() {
    // arrange
    SymmetricKeyParser parser = new SymmetricKeyParser(TEST_KEY1, TEST_KEY2);
    // act
    parser.setPrimaryKey(TEST_KEY2);
    parser.setSecondaryKey(TEST_KEY1);
    // assert
    assertEquals(TEST_KEY2, parser.getPrimaryKeyFinal());
    assertEquals(TEST_KEY1, parser.getSecondaryKeyFinal());
}
Also used : SymmetricKeyParser(com.microsoft.azure.sdk.iot.deps.serializer.SymmetricKeyParser) Test(org.junit.Test)

Example 2 with SymmetricKeyParser

use of com.microsoft.azure.sdk.iot.deps.serializer.SymmetricKeyParser in project azure-iot-sdk-java by Azure.

the class SymmetricKeyParserTest method testToJson.

// Tests_SRS_SymmetricKeyParser_34_007: [The parser shall return a json representation of the provided SymmetricKeyParser.]
@Test
public void testToJson() {
    // arrange
    SymmetricKeyParser parser = new SymmetricKeyParser(TEST_KEY1, TEST_KEY2);
    String expectedJson = "{\"primaryKey\":\"" + TEST_KEY1 + "\",\"secondaryKey\":\"" + TEST_KEY2 + "\"}";
    // act
    String actualJson = parser.toJson();
    // assert
    assertEquals(expectedJson, actualJson);
}
Also used : SymmetricKeyParser(com.microsoft.azure.sdk.iot.deps.serializer.SymmetricKeyParser) Test(org.junit.Test)

Example 3 with SymmetricKeyParser

use of com.microsoft.azure.sdk.iot.deps.serializer.SymmetricKeyParser in project azure-iot-sdk-java by Azure.

the class Tools method addModules.

private static void addModules(Iterable<Module> modules, String connectionString) throws IOException, IotHubException {
    if (modules == null) {
        throw new IllegalArgumentException("modules cannot be null");
    }
    IotHubConnectionString iotHubConnectionString = IotHubConnectionString.createConnectionString(connectionString);
    URL url = getBulkDeviceAddUrl(iotHubConnectionString);
    List<ExportImportDeviceParser> parsers = new ArrayList<>();
    for (Module module : modules) {
        ExportImportDeviceParser exportImportDevice = new ExportImportDeviceParser();
        exportImportDevice.setId(module.getDeviceId());
        exportImportDevice.setModuleId(module.getId());
        AuthenticationParser authenticationParser = new AuthenticationParser();
        if (module.getAuthenticationType() == AuthenticationType.SAS) {
            authenticationParser.setType(AuthenticationTypeParser.SAS);
            authenticationParser.setSymmetricKey(new SymmetricKeyParser(module.getSymmetricKey().getPrimaryKey(), module.getSymmetricKey().getSecondaryKey()));
        } else {
            authenticationParser.setType(AuthenticationTypeParser.SELF_SIGNED);
            authenticationParser.setThumbprint(new X509ThumbprintParser(module.getPrimaryThumbprint(), module.getSecondaryThumbprint()));
        }
        exportImportDevice.setAuthentication(authenticationParser);
        exportImportDevice.setImportMode(IMPORT_MODE_CREATE);
        parsers.add(exportImportDevice);
    }
    ExportImportDevicesParser body = new ExportImportDevicesParser();
    body.setExportImportDevices(parsers);
    bulkRegistryOperation(body.toJson(), url, connectionString);
}
Also used : AuthenticationParser(com.microsoft.azure.sdk.iot.deps.serializer.AuthenticationParser) SymmetricKeyParser(com.microsoft.azure.sdk.iot.deps.serializer.SymmetricKeyParser) ExportImportDeviceParser(com.microsoft.azure.sdk.iot.deps.serializer.ExportImportDeviceParser) ArrayList(java.util.ArrayList) X509ThumbprintParser(com.microsoft.azure.sdk.iot.deps.serializer.X509ThumbprintParser) IotHubConnectionString(com.microsoft.azure.sdk.iot.service.IotHubConnectionString) Module(com.microsoft.azure.sdk.iot.service.Module) URL(java.net.URL)

Example 4 with SymmetricKeyParser

use of com.microsoft.azure.sdk.iot.deps.serializer.SymmetricKeyParser in project azure-iot-sdk-java by Azure.

the class Tools method addDevices.

private static void addDevices(Iterable<Device> devices, String connectionString) throws IOException, IotHubException {
    if (devices == null) {
        throw new IllegalArgumentException("devices cannot be null");
    }
    IotHubConnectionString iotHubConnectionString = IotHubConnectionString.createConnectionString(connectionString);
    URL url = getBulkDeviceAddUrl(iotHubConnectionString);
    List<ExportImportDeviceParser> parsers = new ArrayList<>();
    for (Device device : devices) {
        ExportImportDeviceParser exportImportDevice = new ExportImportDeviceParser();
        exportImportDevice.setId(device.getDeviceId());
        AuthenticationParser authenticationParser = new AuthenticationParser();
        if (device.getAuthenticationType() == AuthenticationType.SAS) {
            authenticationParser.setType(AuthenticationTypeParser.SAS);
            authenticationParser.setSymmetricKey(new SymmetricKeyParser(device.getSymmetricKey().getPrimaryKey(), device.getSymmetricKey().getSecondaryKey()));
        } else {
            authenticationParser.setType(AuthenticationTypeParser.SELF_SIGNED);
            authenticationParser.setThumbprint(new X509ThumbprintParser(device.getPrimaryThumbprint(), device.getSecondaryThumbprint()));
        }
        exportImportDevice.setAuthentication(authenticationParser);
        exportImportDevice.setImportMode(IMPORT_MODE_CREATE);
        parsers.add(exportImportDevice);
    }
    ExportImportDevicesParser body = new ExportImportDevicesParser();
    body.setExportImportDevices(parsers);
    bulkRegistryOperation(body.toJson(), url, connectionString);
}
Also used : AuthenticationParser(com.microsoft.azure.sdk.iot.deps.serializer.AuthenticationParser) SymmetricKeyParser(com.microsoft.azure.sdk.iot.deps.serializer.SymmetricKeyParser) Device(com.microsoft.azure.sdk.iot.service.Device) ExportImportDeviceParser(com.microsoft.azure.sdk.iot.deps.serializer.ExportImportDeviceParser) ArrayList(java.util.ArrayList) X509ThumbprintParser(com.microsoft.azure.sdk.iot.deps.serializer.X509ThumbprintParser) IotHubConnectionString(com.microsoft.azure.sdk.iot.service.IotHubConnectionString) URL(java.net.URL)

Example 5 with SymmetricKeyParser

use of com.microsoft.azure.sdk.iot.deps.serializer.SymmetricKeyParser in project azure-iot-sdk-java by Azure.

the class SymmetricKeyParserTest method setSecondaryKeyNullValueThrowsIllegalArgumentException.

// Tests_SRS_SymmetricKeyParser_34_005: [If the provided secondaryKey value is null, an IllegalArgumentException shall be thrown.]
@Test(expected = IllegalArgumentException.class)
public void setSecondaryKeyNullValueThrowsIllegalArgumentException() {
    // arrange
    SymmetricKeyParser parser = new SymmetricKeyParser("", "");
    // act
    parser.setSecondaryKey(null);
}
Also used : SymmetricKeyParser(com.microsoft.azure.sdk.iot.deps.serializer.SymmetricKeyParser) Test(org.junit.Test)

Aggregations

SymmetricKeyParser (com.microsoft.azure.sdk.iot.deps.serializer.SymmetricKeyParser)9 Test (org.junit.Test)7 AuthenticationParser (com.microsoft.azure.sdk.iot.deps.serializer.AuthenticationParser)3 ExportImportDeviceParser (com.microsoft.azure.sdk.iot.deps.serializer.ExportImportDeviceParser)2 X509ThumbprintParser (com.microsoft.azure.sdk.iot.deps.serializer.X509ThumbprintParser)2 IotHubConnectionString (com.microsoft.azure.sdk.iot.service.IotHubConnectionString)2 URL (java.net.URL)2 ArrayList (java.util.ArrayList)2 Device (com.microsoft.azure.sdk.iot.service.Device)1 Module (com.microsoft.azure.sdk.iot.service.Module)1