|
27 | 27 | import java.time.OffsetDateTime; |
28 | 28 | import java.time.format.DateTimeParseException; |
29 | 29 | import java.util.ArrayList; |
| 30 | +import java.util.Base64; |
30 | 31 | import java.util.HashSet; |
31 | 32 | import java.util.List; |
32 | 33 | import java.util.Map; |
@@ -86,7 +87,8 @@ private record FormatCheck(Predicate<String> isValid, String message) {} |
86 | 87 | new FormatCheck(s -> HOSTNAME.matcher(s).matches(), "not a valid hostname")), |
87 | 88 | Map.entry("ipv4", new FormatCheck(s -> IPV4.matcher(s).matches(), "not a valid ipv4")), |
88 | 89 | Map.entry("ipv6", new FormatCheck(s -> IPV6.matcher(s).matches(), "not a valid ipv6")), |
89 | | - Map.entry("regex", new FormatCheck(DefaultValidator::isRegex, "not a valid regex"))); |
| 90 | + Map.entry("regex", new FormatCheck(DefaultValidator::isRegex, "not a valid regex")), |
| 91 | + Map.entry("byte", new FormatCheck(DefaultValidator::isByte, "not valid base64"))); |
90 | 92 |
|
91 | 93 | private final Function<String, Schema> refResolver; |
92 | 94 | private final ConcurrentMap<String, Pattern> compiledPatterns = new ConcurrentHashMap<>(); |
@@ -211,6 +213,15 @@ private static boolean isRegex(String s) { |
211 | 213 | } |
212 | 214 | } |
213 | 215 |
|
| 216 | + private static boolean isByte(String s) { |
| 217 | + try { |
| 218 | + Base64.getDecoder().decode(s); |
| 219 | + return true; |
| 220 | + } catch (IllegalArgumentException _) { |
| 221 | + return false; |
| 222 | + } |
| 223 | + } |
| 224 | + |
214 | 225 | private static boolean isUriReference(String s) { |
215 | 226 | try { |
216 | 227 | new URI(s); |
|
0 commit comments