/** Test that not setting the any properties returns in an (almost) empty Blob */
 @Test
 public void testExceptionsThrown() {
   ControlParameters controlParameters = new ControlParameters();
   Blob encoded = controlParameters.wireEncode();
   assertEquals(2, encoded.buf().limit());
   // only TLV type 104 and length 0 should be set
 }
Пример #2
0
  /**
   * Add a public key to the identity storage. Also call addIdentity to ensure that the identityName
   * for the key exists.
   *
   * @param keyName The name of the public key to be added.
   * @param keyType Type of the public key to be added.
   * @param publicKeyDer A blob of the public key DER to be added.
   * @throws SecurityException if a key with the keyName already exists.
   */
  public final void addKey(Name keyName, KeyType keyType, Blob publicKeyDer)
      throws SecurityException {
    if (keyName.size() == 0) return;

    checkAddKey(keyName);

    String keyId = keyName.get(-1).toEscapedString();
    Name identityName = keyName.getPrefix(-1);

    addIdentity(identityName);

    try {
      PreparedStatement statement =
          database_.prepareStatement(
              "INSERT INTO Key (identity_name, key_identifier, key_type, public_key) values (?, ?, ?, ?)");
      statement.setString(1, identityName.toUri());
      statement.setString(2, keyId);
      statement.setInt(3, keyType.getNumericType());
      statement.setBytes(4, publicKeyDer.getImmutableArray());

      try {
        statement.executeUpdate();
      } finally {
        statement.close();
      }
    } catch (SQLException exception) {
      throw new SecurityException("BasicIdentityStorage: SQLite error: " + exception);
    }
  }