Accept String IP for convenience

pull/81/head
Richard Körber 2019-03-16 16:58:30 +01:00
parent 548fa4db5e
commit 710d2ca948
No known key found for this signature in database
GPG Key ID: AAB9FD19C78AA3E0
3 changed files with 24 additions and 1 deletions

View File

@ -112,6 +112,22 @@ public class Identifier implements Serializable {
return new Identifier(TYPE_IP, ip.getHostAddress());
}
/**
* Creates a new IP identifier for the given {@link InetAddress}.
*
* @param ip
* IP address as {@link String}
* @return New {@link Identifier}
* @since 2.7
*/
public static Identifier ip(String ip) {
try {
return ip(InetAddress.getByName(ip));
} catch (UnknownHostException ex) {
throw new IllegalArgumentException("Bad IP: " + ip, ex);
}
}
/**
* Returns the identifier type.
*/

View File

@ -88,6 +88,11 @@ public class IdentifierTest {
assertThat(id2.getType(), is(Identifier.TYPE_IP));
assertThat(id2.getValue(), is("2001:db8:85a3:0:0:8a2e:370:7334"));
assertThat(id2.getIP().getHostAddress(), is("2001:db8:85a3:0:0:8a2e:370:7334"));
Identifier id3 = Identifier.ip("192.168.2.99");
assertThat(id3.getType(), is(Identifier.TYPE_IP));
assertThat(id3.getValue(), is("192.168.2.99"));
assertThat(id3.getIP().getHostAddress(), is("192.168.2.99"));
}
@Test(expected = AcmeProtocolException.class)

View File

@ -178,17 +178,19 @@ _acme4j_ supports the [ACME IP](https://tools.ietf.org/html/draft-ietf-acme-ip)
```java
Order order = account.newOrder()
.identifier(Identifier.ip(InetAddress.getByName("192.168.1.2")))
.identifier(Identifier.ip("192.168.2.3")) // for your convenience
.identifier(Identifier.dns("example.org"))
.create();
```
The example also shows how to add domain names as DNS `Identifier` objects. Adding domain names via `domain()` is just a shortcut notation for it.
The `CSRBuilder` also accepts IP addresses for generating the CSR:
The `CSRBuilder` also accepts IP addresses and `Identifier` for generating the CSR:
```java
CSRBuilder csrb = new CSRBuilder();
csrb.addIP(InetAddress.getByName("192.168.1.2"));
csrb.addIdentifier(Identifier.ip("192.168.2.3"));
csrb.sign(domainKeyPair);
byte[] csr = csrb.getEncoded();
```