PemReader Class — netty Architecture
Architecture documentation for the PemReader class in PemReader.java from the netty codebase.
Entity Profile
Dependency Diagram
graph TD ce674e6c_624f_916e_3b83_54597564e644["PemReader"] 2e1dd444_53a7_42ac_0fb3_69425a4acd3f["PemReader.java"] ce674e6c_624f_916e_3b83_54597564e644 -->|defined in| 2e1dd444_53a7_42ac_0fb3_69425a4acd3f 4487ad55_ba97_d8f1_1173_6b9f3def1ddf["readCertificates()"] ce674e6c_624f_916e_3b83_54597564e644 -->|method| 4487ad55_ba97_d8f1_1173_6b9f3def1ddf 7144d274_4483_d139_bedc_b6a2cfbb6d4d["ByteBuf()"] ce674e6c_624f_916e_3b83_54597564e644 -->|method| 7144d274_4483_d139_bedc_b6a2cfbb6d4d a16e84bd_42a9_57f4_1e10_7a403281533c["KeyException()"] ce674e6c_624f_916e_3b83_54597564e644 -->|method| a16e84bd_42a9_57f4_1e10_7a403281533c 899709c3_795b_d604_4889_2be81b26570b["String()"] ce674e6c_624f_916e_3b83_54597564e644 -->|method| 899709c3_795b_d604_4889_2be81b26570b 0104c781_3147_37cb_c034_af28b9e20d6b["PemReader()"] ce674e6c_624f_916e_3b83_54597564e644 -->|method| 0104c781_3147_37cb_c034_af28b9e20d6b
Relationship Graph
Source Code
handler/src/main/java/io/netty/handler/ssl/PemReader.java lines 40–165
final class PemReader {
private static final Pattern CERT_HEADER = Pattern.compile(
"-+BEGIN\\s[^-\\r\\n]*CERTIFICATE[^-\\r\\n]*-+(?:\\s|\\r|\\n)+");
private static final Pattern CERT_FOOTER = Pattern.compile(
"-+END\\s[^-\\r\\n]*CERTIFICATE[^-\\r\\n]*-+(?:\\s|\\r|\\n)*");
private static final Pattern KEY_HEADER = Pattern.compile(
"-+BEGIN\\s[^-\\r\\n]*PRIVATE\\s+KEY[^-\\r\\n]*-+(?:\\s|\\r|\\n)+");
private static final Pattern KEY_FOOTER = Pattern.compile(
"-+END\\s[^-\\r\\n]*PRIVATE\\s+KEY[^-\\r\\n]*-+(?:\\s|\\r|\\n)*");
private static final Pattern BODY = Pattern.compile("[a-z0-9+/=][a-z0-9+/=\\r\\n]*", Pattern.CASE_INSENSITIVE);
static ByteBuf[] readCertificates(File file) throws CertificateException {
try (InputStream in = new FileInputStream(file)) {
return readCertificates(in);
} catch (IOException e) {
throw new CertificateException("could not find certificate file: " + file);
}
}
static ByteBuf[] readCertificates(InputStream in) throws CertificateException {
String content;
try {
content = readContent(in);
} catch (IOException e) {
throw new CertificateException("failed to read certificate input stream", e);
}
List<ByteBuf> certs = new ArrayList<ByteBuf>();
Matcher m = CERT_HEADER.matcher(content);
int start = 0;
for (;;) {
if (!m.find(start)) {
break;
}
// Here and below it's necessary to save the position as it is reset
// after calling usePattern() on Android due to a bug.
//
// See https://issuetracker.google.com/issues/293206296
start = m.end();
m.usePattern(BODY);
if (!m.find(start)) {
break;
}
ByteBuf base64 = Unpooled.copiedBuffer(m.group(0), CharsetUtil.US_ASCII);
start = m.end();
m.usePattern(CERT_FOOTER);
if (!m.find(start)) {
// Certificate is incomplete.
break;
}
ByteBuf der = Base64.decode(base64);
base64.release();
certs.add(der);
start = m.end();
m.usePattern(CERT_HEADER);
}
if (certs.isEmpty()) {
throw new CertificateException("found no certificates in input stream");
}
return certs.toArray(new ByteBuf[0]);
}
static ByteBuf readPrivateKey(File file) throws KeyException {
try (InputStream in = new FileInputStream(file)) {
return readPrivateKey(in);
} catch (IOException e) {
throw new KeyException("could not find key file: " + file);
}
}
static ByteBuf readPrivateKey(InputStream in) throws KeyException {
String content;
try {
content = readContent(in);
} catch (IOException e) {
Source
Frequently Asked Questions
What is the PemReader class?
PemReader is a class in the netty codebase, defined in handler/src/main/java/io/netty/handler/ssl/PemReader.java.
Where is PemReader defined?
PemReader is defined in handler/src/main/java/io/netty/handler/ssl/PemReader.java at line 40.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free