public void test_ctor_0arg() throws UnknownHostException { KEYRecord ar = new KEYRecord(); assertNull(ar.getName()); assertEquals(0, ar.getType()); assertEquals(0, ar.getDClass()); assertEquals(0, ar.getTTL()); assertEquals(0, ar.getAlgorithm()); assertEquals(0, ar.getFlags()); assertEquals(0, ar.getFootprint()); assertEquals(0, ar.getProtocol()); assertNull(ar.getKey()); }
public void test_ctor_7arg() throws TextParseException { Name n = Name.fromString("My.Absolute.Name."); Name r = Name.fromString("My.Relative.Name"); byte[] key = new byte[] {0, 1, 3, 5, 7, 9}; KEYRecord kr = new KEYRecord(n, DClass.IN, 0x24AC, 0x9832, 0x12, 0x67, key); assertEquals(n, kr.getName()); assertEquals(Type.KEY, kr.getType()); assertEquals(DClass.IN, kr.getDClass()); assertEquals(0x24AC, kr.getTTL()); assertEquals(0x9832, kr.getFlags()); assertEquals(0x12, kr.getProtocol()); assertEquals(0x67, kr.getAlgorithm()); assertTrue(Arrays.equals(key, kr.getKey())); // a relative name try { new KEYRecord(r, DClass.IN, 0x24AC, 0x9832, 0x12, 0x67, key); fail("RelativeNameException not thrown"); } catch (RelativeNameException e) { } }
/** Converts a KEY record into a PublicKey */ public static PublicKey parseRecord(KEYRecord r) { int alg = r.getAlgorithm(); byte[] data = r.getKey(); return parseRecord(alg, data); }
public void test_rdataFromString() throws IOException, TextParseException { // basic KEYRecord kr = new KEYRecord(); Tokenizer st = new Tokenizer("NOAUTH|ZONE|FLAG10 EMAIL RSASHA1 AQIDBAUGBwgJ"); kr.rdataFromString(st, null); assertEquals( KEYRecord.Flags.NOAUTH | KEYRecord.Flags.FLAG10 | KEYRecord.Flags.ZONE, kr.getFlags()); assertEquals(KEYRecord.Protocol.EMAIL, kr.getProtocol()); assertEquals(DNSSEC.Algorithm.RSASHA1, kr.getAlgorithm()); assertTrue(Arrays.equals(new byte[] {1, 2, 3, 4, 5, 6, 7, 8, 9}, kr.getKey())); // basic w/o key kr = new KEYRecord(); st = new Tokenizer("NOAUTH|NOKEY|FLAG10 TLS ECC"); kr.rdataFromString(st, null); assertEquals( KEYRecord.Flags.NOAUTH | KEYRecord.Flags.FLAG10 | KEYRecord.Flags.NOKEY, kr.getFlags()); assertEquals(KEYRecord.Protocol.TLS, kr.getProtocol()); assertEquals(DNSSEC.Algorithm.ECC, kr.getAlgorithm()); assertNull(kr.getKey()); // invalid flags kr = new KEYRecord(); st = new Tokenizer("NOAUTH|ZONE|JUNK EMAIL RSASHA1 AQIDBAUGBwgJ"); try { kr.rdataFromString(st, null); fail("TextParseException not thrown"); } catch (TextParseException e) { } // invalid protocol kr = new KEYRecord(); st = new Tokenizer("NOAUTH|ZONE RSASHA1 ECC AQIDBAUGBwgJ"); try { kr.rdataFromString(st, null); fail("TextParseException not thrown"); } catch (TextParseException e) { } // invalid algorithm kr = new KEYRecord(); st = new Tokenizer("NOAUTH|ZONE EMAIL ZONE AQIDBAUGBwgJ"); try { kr.rdataFromString(st, null); fail("TextParseException not thrown"); } catch (TextParseException e) { } }
public void test_getObject() { KEYRecord ar = new KEYRecord(); Record r = ar.getObject(); assertTrue(r instanceof KEYRecord); }