Class TerminalSafe
java.lang.Object
co.ankatech.ankasecure.keymanagement.security.TerminalSafe
Renders a server-supplied string so it can enter an exception message, a log line or terminal output
without changing what the operator's terminal shows or does.
Every value read from an HTTP response (a body member, a header, a problem type,
title or detail, an OAuth error, a metadata value, an enum wire value) passes
through text(String), or uri(String) when it is a URI, before it is concatenated into
any of those channels. A Location header is never rendered at all, by either method.
- A code point that is an ISO control (C0 including TAB, CR and LF; DEL; C1), a format character
(bidirectional controls and isolates, zero-width characters, the soft hyphen, the byte order mark,
tag characters) or a line or paragraph separator becomes a visible escape: a backslash,
uand four uppercase hexadecimal digits, one per UTF-16 unit. - A lone surrogate becomes U+FFFD; a valid surrogate pair is kept.
- The rendering is capped at 512 code points of output; an escape counts as
six and is never split. A capped rendering ends with the ASCII marker
...[truncated](three full stops), outside the cap. - Nothing is decoded:
%0D%0Astays as it is.
Fields an exception keeps for programmatic use (such as its problem detail) hold the server's
value; whoever prints them renders them here.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intThe most code points a rendering holds before the truncation marker.static final StringAppended to a rendering cut at the cap, in ASCII: three full stops, then[truncated].static final StringThe rendering of a value that is not an absolute URI with a scheme and a host. -
Method Summary
Modifier and TypeMethodDescriptionstatic booleanisEscaped(int codePoint) Whether a code point is rendered as a visible escape: an ISO control, a format character, a line separator or a paragraph separator.static StringRenders a server-supplied string.static StringRenders a server-supplied URI from its parsed parts only:scheme://host[:port][path], the host converted to ASCII (punycode), the path as received (still percent-encoded).
-
Field Details
-
MAX_CODE_POINTS
public static final int MAX_CODE_POINTSThe most code points a rendering holds before the truncation marker.- See Also:
-
TRUNCATED
Appended to a rendering cut at the cap, in ASCII: three full stops, then[truncated].- See Also:
-
UNPARSEABLE
The rendering of a value that is not an absolute URI with a scheme and a host.- See Also:
-
-
Method Details
-
text
Renders a server-supplied string.- Parameters:
value- the value, possiblynull- Returns:
- the terminal-safe rendering; empty for
null
-
uri
Renders a server-supplied URI from its parsed parts only:scheme://host[:port][path], the host converted to ASCII (punycode), the path as received (still percent-encoded). User information, query and fragment never appear. The result is all ASCII: on top of whattext(String)escapes, every code point of the path outside U+0020 to U+007E is a visible escape, one per UTF-16 unit, but a lone surrogate, which is U+FFFD as intext(String); the same cap applies. A port, after the authority's last colon outside an IPv6 literal, is one to five ASCII digits whose value is at most 65535, rendered as its value (leading zeros dropped).- Parameters:
value- the value, possiblynull- Returns:
- the rendering, or
UNPARSEABLEwhen the value does not parse as an absolute URI with a scheme and a host, or names an empty, non-ASCII, longer or out-of-range port
-
isEscaped
public static boolean isEscaped(int codePoint) Whether a code point is rendered as a visible escape: an ISO control, a format character, a line separator or a paragraph separator.- Parameters:
codePoint- the code point- Returns:
truewhentext(String)escapes it
-