|
@@ -30,7 +30,9 @@ import java.security.NoSuchAlgorithmException;
|
|
import java.text.DateFormat;
|
|
import java.text.DateFormat;
|
|
import java.text.SimpleDateFormat;
|
|
import java.text.SimpleDateFormat;
|
|
import java.util.Date;
|
|
import java.util.Date;
|
|
|
|
+import java.util.HashMap;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
|
+import java.util.Map;
|
|
|
|
|
|
import static org.junit.Assert.assertEquals;
|
|
import static org.junit.Assert.assertEquals;
|
|
import static org.junit.Assert.assertNull;
|
|
import static org.junit.Assert.assertNull;
|
|
@@ -73,7 +75,7 @@ public class TestKeyProvider {
|
|
DateFormat format = new SimpleDateFormat("y/m/d");
|
|
DateFormat format = new SimpleDateFormat("y/m/d");
|
|
Date date = format.parse("2013/12/25");
|
|
Date date = format.parse("2013/12/25");
|
|
KeyProvider.Metadata meta = new KeyProvider.Metadata("myCipher", 100, null,
|
|
KeyProvider.Metadata meta = new KeyProvider.Metadata("myCipher", 100, null,
|
|
- date, 123);
|
|
|
|
|
|
+ null, date, 123);
|
|
assertEquals("myCipher", meta.getCipher());
|
|
assertEquals("myCipher", meta.getCipher());
|
|
assertEquals(100, meta.getBitLength());
|
|
assertEquals(100, meta.getBitLength());
|
|
assertNull(meta.getDescription());
|
|
assertNull(meta.getDescription());
|
|
@@ -83,6 +85,7 @@ public class TestKeyProvider {
|
|
assertEquals(meta.getCipher(), second.getCipher());
|
|
assertEquals(meta.getCipher(), second.getCipher());
|
|
assertEquals(meta.getBitLength(), second.getBitLength());
|
|
assertEquals(meta.getBitLength(), second.getBitLength());
|
|
assertNull(second.getDescription());
|
|
assertNull(second.getDescription());
|
|
|
|
+ assertTrue(second.getAttributes().isEmpty());
|
|
assertEquals(meta.getCreated(), second.getCreated());
|
|
assertEquals(meta.getCreated(), second.getCreated());
|
|
assertEquals(meta.getVersions(), second.getVersions());
|
|
assertEquals(meta.getVersions(), second.getVersions());
|
|
int newVersion = second.addVersion();
|
|
int newVersion = second.addVersion();
|
|
@@ -93,17 +96,21 @@ public class TestKeyProvider {
|
|
//Metadata with description
|
|
//Metadata with description
|
|
format = new SimpleDateFormat("y/m/d");
|
|
format = new SimpleDateFormat("y/m/d");
|
|
date = format.parse("2013/12/25");
|
|
date = format.parse("2013/12/25");
|
|
|
|
+ Map<String, String> attributes = new HashMap<String, String>();
|
|
|
|
+ attributes.put("a", "A");
|
|
meta = new KeyProvider.Metadata("myCipher", 100,
|
|
meta = new KeyProvider.Metadata("myCipher", 100,
|
|
- "description", date, 123);
|
|
|
|
|
|
+ "description", attributes, date, 123);
|
|
assertEquals("myCipher", meta.getCipher());
|
|
assertEquals("myCipher", meta.getCipher());
|
|
assertEquals(100, meta.getBitLength());
|
|
assertEquals(100, meta.getBitLength());
|
|
assertEquals("description", meta.getDescription());
|
|
assertEquals("description", meta.getDescription());
|
|
|
|
+ assertEquals(attributes, meta.getAttributes());
|
|
assertEquals(date, meta.getCreated());
|
|
assertEquals(date, meta.getCreated());
|
|
assertEquals(123, meta.getVersions());
|
|
assertEquals(123, meta.getVersions());
|
|
second = new KeyProvider.Metadata(meta.serialize());
|
|
second = new KeyProvider.Metadata(meta.serialize());
|
|
assertEquals(meta.getCipher(), second.getCipher());
|
|
assertEquals(meta.getCipher(), second.getCipher());
|
|
assertEquals(meta.getBitLength(), second.getBitLength());
|
|
assertEquals(meta.getBitLength(), second.getBitLength());
|
|
assertEquals(meta.getDescription(), second.getDescription());
|
|
assertEquals(meta.getDescription(), second.getDescription());
|
|
|
|
+ assertEquals(meta.getAttributes(), second.getAttributes());
|
|
assertEquals(meta.getCreated(), second.getCreated());
|
|
assertEquals(meta.getCreated(), second.getCreated());
|
|
assertEquals(meta.getVersions(), second.getVersions());
|
|
assertEquals(meta.getVersions(), second.getVersions());
|
|
newVersion = second.addVersion();
|
|
newVersion = second.addVersion();
|
|
@@ -117,15 +124,19 @@ public class TestKeyProvider {
|
|
Configuration conf = new Configuration();
|
|
Configuration conf = new Configuration();
|
|
conf.set(KeyProvider.DEFAULT_CIPHER_NAME, "myCipher");
|
|
conf.set(KeyProvider.DEFAULT_CIPHER_NAME, "myCipher");
|
|
conf.setInt(KeyProvider.DEFAULT_BITLENGTH_NAME, 512);
|
|
conf.setInt(KeyProvider.DEFAULT_BITLENGTH_NAME, 512);
|
|
|
|
+ Map<String, String> attributes = new HashMap<String, String>();
|
|
|
|
+ attributes.put("a", "A");
|
|
KeyProvider.Options options = KeyProvider.options(conf);
|
|
KeyProvider.Options options = KeyProvider.options(conf);
|
|
assertEquals("myCipher", options.getCipher());
|
|
assertEquals("myCipher", options.getCipher());
|
|
assertEquals(512, options.getBitLength());
|
|
assertEquals(512, options.getBitLength());
|
|
options.setCipher("yourCipher");
|
|
options.setCipher("yourCipher");
|
|
options.setDescription("description");
|
|
options.setDescription("description");
|
|
|
|
+ options.setAttributes(attributes);
|
|
options.setBitLength(128);
|
|
options.setBitLength(128);
|
|
assertEquals("yourCipher", options.getCipher());
|
|
assertEquals("yourCipher", options.getCipher());
|
|
assertEquals(128, options.getBitLength());
|
|
assertEquals(128, options.getBitLength());
|
|
assertEquals("description", options.getDescription());
|
|
assertEquals("description", options.getDescription());
|
|
|
|
+ assertEquals(attributes, options.getAttributes());
|
|
options = KeyProvider.options(new Configuration());
|
|
options = KeyProvider.options(new Configuration());
|
|
assertEquals(KeyProvider.DEFAULT_CIPHER, options.getCipher());
|
|
assertEquals(KeyProvider.DEFAULT_CIPHER, options.getCipher());
|
|
assertEquals(KeyProvider.DEFAULT_BITLENGTH, options.getBitLength());
|
|
assertEquals(KeyProvider.DEFAULT_BITLENGTH, options.getBitLength());
|
|
@@ -167,7 +178,7 @@ public class TestKeyProvider {
|
|
|
|
|
|
@Override
|
|
@Override
|
|
public Metadata getMetadata(String name) throws IOException {
|
|
public Metadata getMetadata(String name) throws IOException {
|
|
- return new Metadata(CIPHER, 128, "description", new Date(), 0);
|
|
|
|
|
|
+ return new Metadata(CIPHER, 128, "description", null, new Date(), 0);
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|