Skip to content

Commit

Permalink
update abnf and regex for rfc4291
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastian-toepfer committed Dec 5, 2024
1 parent fc43dc5 commit 7c5f3ca
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ final class Formats {
Stream.of(
new RfcBasedFormat("email", new Rfc5321(), "mailbox"),
new RfcBasedFormat("ipv4", new Rfc2673(), "dotted-quad"),
new RfcBasedFormat("ipv6", new Rfc4291(), "address")
new RfcBasedFormat("ipv6", new Rfc4291(), "IPv6address")
)
)
.map(Format.class::cast)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,30 @@
public final class Rfc4291 implements Rfc {

private static final Map<String, Pattern> RULES = Map.of(
"address",
"IPv6address",
Pattern.compile(
"^(([0-9A-Fa-f]{1,4}(\\:[0-9A-Fa-f]{1,4}){7})|" +
"([0-9A-Fa-f]{1,4}(\\:[0-9A-Fa-f]{1,4}){0,5})*\\:\\:([0-9A-Fa-f]{1,4}(\\:[0-9A-Fa-f]{1,4}){0,5})*|" +
"(((([0-9A-Fa-f]{1,4}(\\:[0-9A-Fa-f]{1,4}){5})\\:)|" +
"([0-9A-Fa-f]{1,4}(\\:[0-9A-Fa-f]{1,4}){0,4})*\\:\\:([0-9A-Fa-f]{1,4}(\\:[0-9A-Fa-f]{1,4}){0,4})*)" +
"\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}))$"
"^(([0-9A-Fa-f]{1,4}\\:){6}(([0-9A-Fa-f]{1,4}\\:[0-9A-Fa-f]{1,4})|(\\d|[1-9]\\d|1\\d{2}|2[0-4]\\d|" +
"25[0-5])\\.(\\d|[1-9]\\d|1\\d{2}|2[0-4]\\d|25[0-5])\\.(\\d|[1-9]\\d|1\\d{2}|2[0-4]\\d|" +
"25[0-5])\\.(\\d|[1-9]\\d|1\\d{2}|2[0-4]\\d|25[0-5]))|\\:\\:([0-9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\d|[1-9]\\d|1\\d{2}|" +
"2[0-4]\\d|25[0-5]))|(([0-9A-Fa-f]{1,4}\\:){0,3}[0-9A-Fa-f]{1,4})?\\:\\:[0-9A-Fa-f]{1,4}\\:" +
"(([0-9A-Fa-f]{1,4}\\:[0-9A-Fa-f]{1,4})|(\\d|[1-9]\\d|1\\d{2}|2[0-4]\\d|25[0-5])\\.(\\d|[1-9]\\d|" +
"1\\d{2}|2[0-4]\\d|25[0-5])\\.(\\d|[1-9]\\d|1\\d{2}|2[0-4]\\d|25[0-5])\\.(\\d|[1-9]\\d|1\\d{2}|" +
"2[0-4]\\d|25[0-5]))|(([0-9A-Fa-f]{1,4}\\:){0,4}[0-9A-Fa-f]{1,4})?\\:\\:(([0-9A-Fa-f]{1,4}\\:" +
"[0-9A-Fa-f]{1,4})|(\\d|[1-9]\\d|1\\d{2}|2[0-4]\\d|25[0-5])\\.(\\d|[1-9]\\d|1\\d{2}|2[0-4]\\d|" +
"25[0-5])\\.(\\d|[1-9]\\d|1\\d{2}|2[0-4]\\d|25[0-5])\\.(\\d|[1-9]\\d|1\\d{2}|2[0-4]\\d|25[0-5]))|" +
"(([0-9A-Fa-f]{1,4}\\:){0,5}[0-9A-Fa-f]{1,4})?\\:\\:[0-9A-Fa-f]{1,4}|(([0-9A-Fa-f]{1,4}\\:){0,6}" +
"[0-9A-Fa-f]{1,4})?\\:\\:)$"
)
);

Expand Down
30 changes: 23 additions & 7 deletions vocabulary/format-assertion/src/main/resources/rfc/rfc4291
Original file line number Diff line number Diff line change
@@ -1,7 +1,23 @@
; selfmade :( -> not effectiv
dotted-quad = decbyte "." decbyte "." decbyte "." decbyte
decbyte = 1*3DIGIT
address = (hexbytes 7(":" hexbytes) ) / *(hexbytes *5(":" hexbytes)) zeros *(hexbytes *5(":" hexbytes)) / ((((hexbytes 5(":" hexbytes) ) ":") / *(hexbytes *4(":" hexbytes)) zeros *(hexbytes *4(":" hexbytes))) dotted-quad)
zeros = "::"
hexbytes = 1*4hexValue
hexValue = DIGIT / %x41-46 / %x61-66
IPv6address = 6( h16 ":" ) ls32
/ "::" 5( h16 ":" ) ls32
/ [ h16 ] "::" 4( h16 ":" ) ls32
/ [ *1( h16 ":" ) h16 ] "::" 3( h16 ":" ) ls32
/ [ *2( h16 ":" ) h16 ] "::" 2( h16 ":" ) ls32
/ [ *3( h16 ":" ) h16 ] "::" h16 ":" ls32
/ [ *4( h16 ":" ) h16 ] "::" ls32
/ [ *5( h16 ":" ) h16 ] "::" h16
/ [ *6( h16 ":" ) h16 ] "::"

ls32 = ( h16 ":" h16 ) / IPv4address
; least-significant 32 bits of address

h16 = 1*4HEXDIG
; 16 bits of address represented in hexadecimal

IPv4address = dec-octet "." dec-octet "." dec-octet "." dec-octet

dec-octet = DIGIT ; 0-9
/ %x31-39 DIGIT ; 10-99
/ "1" 2DIGIT ; 100-199
/ "2" %x30-34 DIGIT ; 200-249
/ "25" %x30-35 ; 250-255

0 comments on commit 7c5f3ca

Please sign in to comment.