Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions src/main/java/org/xbill/DNS/CAARecord.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package org.xbill.DNS;

import java.io.IOException;
import java.nio.charset.StandardCharsets;

/**
* Certification Authority Authorization
Expand Down Expand Up @@ -78,13 +79,29 @@ public int getFlags() {
}

/** Returns the tag. */
public String getTag(boolean escape) {
return escape ? byteArrayToString(tag, false) : new String(tag, StandardCharsets.UTF_8);
}

public String getTag() {
return byteArrayToString(tag, false);
return getTag(true);
}

public byte[] getTagAsByteArray() {
return tag;
}

/** Returns the value */
public String getValue(boolean escape) {
return escape ? byteArrayToString(value, false) : new String(value, StandardCharsets.UTF_8);
}

public String getValue() {
return byteArrayToString(value, false);
return getValue(true);
}

public byte[] getValueAsByteArray() {
return value;
}

@Override
Expand Down
21 changes: 19 additions & 2 deletions src/main/java/org/xbill/DNS/HINFORecord.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package org.xbill.DNS;

import java.io.IOException;
import java.nio.charset.StandardCharsets;

/**
* Host Information - describes the CPU and OS of a host
Expand Down Expand Up @@ -52,13 +53,29 @@ protected void rdataFromString(Tokenizer st, Name origin) throws IOException {
}

/** Returns the host's CPU */
public String getCPU(boolean escape) {
return escape ? byteArrayToString(cpu, false) : new String(cpu, StandardCharsets.UTF_8);
}

public String getCPU() {
return byteArrayToString(cpu, false);
return getCPU(true);
}

public byte[] getCPUAsByteArray() {
return cpu;
}

/** Returns the host's OS */
public String getOS(boolean escape) {
return escape ? byteArrayToString(os, false) : new String(os, StandardCharsets.UTF_8);
}

public String getOS() {
return byteArrayToString(os, false);
return getOS(true);
}

public byte[] getOSAsByteArray() {
return os;
}

@Override
Expand Down
25 changes: 22 additions & 3 deletions src/main/java/org/xbill/DNS/ISDNRecord.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package org.xbill.DNS;

import java.io.IOException;
import java.nio.charset.StandardCharsets;

/**
* ISDN - identifies the ISDN number and subaddress associated with a name.
Expand Down Expand Up @@ -60,16 +61,34 @@ protected void rdataFromString(Tokenizer st, Name origin) throws IOException {
}

/** Returns the ISDN number associated with the domain. */
public String getAddress(boolean escape) {
return escape ? byteArrayToString(address, false) : new String(address, StandardCharsets.UTF_8);
}

public String getAddress() {
return byteArrayToString(address, false);
return getAddress(true);
}

public byte[] getAddressAsByteArray() {
return address;
}

/** Returns the ISDN subaddress, or null if there is none. */
public String getSubAddress() {
public String getSubAddress(boolean escape) {
if (subAddress == null) {
return null;
}
return byteArrayToString(subAddress, false);
return escape
? byteArrayToString(subAddress, false)
: new String(subAddress, StandardCharsets.UTF_8);
}

public String getSubAddress() {
return getSubAddress(true);
}

public byte[] getSubAddressAsByteArray() {
return subAddress;
}

@Override
Expand Down
31 changes: 28 additions & 3 deletions src/main/java/org/xbill/DNS/NAPTRRecord.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package org.xbill.DNS;

import java.io.IOException;
import java.nio.charset.StandardCharsets;

/**
* Name Authority Pointer Record - specifies rewrite rule, that when applied to an existing string
Expand Down Expand Up @@ -111,18 +112,42 @@ public int getPreference() {
}

/** Returns flags */
public String getFlags(boolean escape) {
return escape ? byteArrayToString(flags, false) : new String(flags, StandardCharsets.UTF_8);
}

public String getFlags() {
return byteArrayToString(flags, false);
return getFlags(true);
}

public byte[] getFlagsAsByteArray() {
return flags;
}

/** Returns service */
public String getService(boolean escape) {
return escape ? byteArrayToString(service, false) : new String(service, StandardCharsets.UTF_8);
}

public String getService() {
return byteArrayToString(service, false);
return getService(true);
}

public byte[] getServiceAsByteArray() {
return service;
}

/** Returns regexp */
public String getRegexp(boolean escape) {
return escape ? byteArrayToString(regexp, false) : new String(regexp, StandardCharsets.UTF_8);
}

public String getRegexp() {
return byteArrayToString(regexp, false);
return getRegexp(true);
}

public byte[] getRegexpAsByteArray() {
return regexp;
}

/** Returns the replacement domain-name */
Expand Down
11 changes: 10 additions & 1 deletion src/main/java/org/xbill/DNS/NSAPRecord.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import org.xbill.DNS.utils.base16;

/**
Expand Down Expand Up @@ -79,8 +80,16 @@ protected void rdataFromString(Tokenizer st, Name origin) throws IOException {
}

/** Returns the NSAP address. */
public String getAddress(boolean escape) {
return escape ? byteArrayToString(address, false) : new String(address, StandardCharsets.UTF_8);
}

public String getAddress() {
return byteArrayToString(address, false);
return getAddress(true);
}

public byte[] getAddressAsByteArray() {
return address;
}

@Override
Expand Down
10 changes: 8 additions & 2 deletions src/main/java/org/xbill/DNS/TXTBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package org.xbill.DNS;

import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
Expand Down Expand Up @@ -94,14 +95,19 @@ protected String rrToString() {
*
* @return A list of Strings corresponding to the text strings.
*/
public List<String> getStrings() {
public List<String> getStrings(boolean escape) {
List<String> list = new ArrayList<>(strings.size());
for (byte[] string : strings) {
list.add(byteArrayToString(string, false));
list.add(
escape ? byteArrayToString(string, false) : new String(string, StandardCharsets.UTF_8));
}
return list;
}

public List<String> getStrings() {
return getStrings(true);
}

/**
* Returns the text strings
*
Expand Down
11 changes: 10 additions & 1 deletion src/main/java/org/xbill/DNS/URIRecord.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
package org.xbill.DNS;

import java.io.IOException;
import java.nio.charset.StandardCharsets;

/**
* Uniform Resource Identifier (URI) DNS Resource Record
Expand Down Expand Up @@ -79,8 +80,16 @@ public int getWeight() {
}

/** Returns the target URI */
public String getTarget(boolean escape) {
return escape ? byteArrayToString(target, false) : new String(target, StandardCharsets.UTF_8);
}

public String getTarget() {
return byteArrayToString(target, false);
return getTarget(true);
}

public byte[] getTargetAsByteArray() {
return target;
}

@Override
Expand Down
11 changes: 10 additions & 1 deletion src/main/java/org/xbill/DNS/X25Record.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package org.xbill.DNS;

import java.io.IOException;
import java.nio.charset.StandardCharsets;

/**
* X25 - identifies the PSDN (Public Switched Data Network) address in the X.121 numbering plan
Expand Down Expand Up @@ -59,8 +60,16 @@ protected void rdataFromString(Tokenizer st, Name origin) throws IOException {
}

/** Returns the X.25 PSDN address. */
public String getAddress(boolean escape) {
return escape ? byteArrayToString(address, false) : new String(address, StandardCharsets.UTF_8);
}

public String getAddress() {
return byteArrayToString(address, false);
return getAddress(true);
}

public byte[] getAddressAsByteArray() {
return address;
}

@Override
Expand Down
8 changes: 8 additions & 0 deletions src/test/java/org/xbill/DNS/CAARecordTest.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
// SPDX-License-Identifier: BSD-3-Clause
package org.xbill.DNS;

import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;

import java.io.IOException;
import java.nio.charset.StandardCharsets;
import org.junit.jupiter.api.Test;

class CAARecordTest {
Expand All @@ -16,7 +18,9 @@ void ctor_6arg() {
CAARecord caa = new CAARecord(n, DClass.IN, 0, CAARecord.Flags.IssuerCritical, "", "");
assertEquals(CAARecord.Flags.IssuerCritical, caa.getFlags());
assertEquals("", caa.getTag());
assertEquals(0, caa.getTagAsByteArray().length);
assertEquals("", caa.getValue());
assertEquals(0, caa.getValueAsByteArray().length);

String data = new String(new char[256]);
IllegalArgumentException thrown =
Expand All @@ -32,6 +36,10 @@ void rdataFromString() throws IOException {
CAARecord caa = new CAARecord();
caa.rdataFromString(t, null);
assertEquals("issue", caa.getTag());
assertEquals("issue", caa.getTag(false));
assertArrayEquals("issue".getBytes(StandardCharsets.UTF_8), caa.getTagAsByteArray());
assertEquals("entrust.net", caa.getValue());
assertEquals("entrust.net", caa.getValue(false));
assertArrayEquals("entrust.net".getBytes(StandardCharsets.UTF_8), caa.getValueAsByteArray());
}
}
3 changes: 3 additions & 0 deletions src/test/java/org/xbill/DNS/HINFORecordTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import static org.junit.jupiter.api.Assertions.assertThrows;

import java.io.IOException;
import java.nio.charset.StandardCharsets;
import org.junit.jupiter.api.Test;

class HINFORecordTest {
Expand Down Expand Up @@ -120,7 +121,9 @@ void rdataFromString() throws IOException {
HINFORecord dr = new HINFORecord();
dr.rdataFromString(t, null);
assertEquals(cpu, dr.getCPU());
assertArrayEquals(cpu.getBytes(StandardCharsets.UTF_8), dr.getCPUAsByteArray());
assertEquals(os, dr.getOS());
assertArrayEquals(os.getBytes(StandardCharsets.UTF_8), dr.getOSAsByteArray());
}

@Test
Expand Down
10 changes: 8 additions & 2 deletions src/test/java/org/xbill/DNS/ISDNRecordTest.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
// SPDX-License-Identifier: BSD-3-Clause
package org.xbill.DNS;

import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;

import java.io.IOException;
import java.nio.charset.StandardCharsets;
import org.junit.jupiter.api.Test;

class ISDNRecordTest {
Expand All @@ -12,9 +14,13 @@ class ISDNRecordTest {

@Test
void ctor_5arg() {
ISDNRecord isdn = new ISDNRecord(n, DClass.IN, 0, "foo", "bar");
assertEquals("foo", isdn.getAddress());
ISDNRecord isdn = new ISDNRecord(n, DClass.IN, 0, "foo\\\"", "bar");
assertEquals("foo\\\"", isdn.getAddress());
assertEquals("foo\"", isdn.getAddress(false));
assertArrayEquals("foo\"".getBytes(StandardCharsets.UTF_8), isdn.getAddressAsByteArray());
assertEquals("bar", isdn.getSubAddress());
assertEquals("bar", isdn.getSubAddress(false));
assertArrayEquals("bar".getBytes(StandardCharsets.UTF_8), isdn.getSubAddressAsByteArray());
}

@Test
Expand Down
Loading
Loading