68 lines
2.1 KiB
Java
68 lines
2.1 KiB
Java
|
package org.bouncycastle.util.io.pem;
|
||
|
|
||
|
import java.io.BufferedReader;
|
||
|
import java.io.IOException;
|
||
|
import java.io.Reader;
|
||
|
import java.util.ArrayList;
|
||
|
import org.bouncycastle.util.encoders.Base64;
|
||
|
|
||
|
/* loaded from: classes6.dex */
|
||
|
public class PemReader extends BufferedReader {
|
||
|
private static final String BEGIN = "-----BEGIN ";
|
||
|
private static final String END = "-----END ";
|
||
|
|
||
|
public PemObject readPemObject() throws IOException {
|
||
|
String readLine;
|
||
|
do {
|
||
|
readLine = readLine();
|
||
|
if (readLine == null) {
|
||
|
break;
|
||
|
}
|
||
|
} while (!readLine.startsWith(BEGIN));
|
||
|
if (readLine == null) {
|
||
|
return null;
|
||
|
}
|
||
|
String substring = readLine.substring(11);
|
||
|
int indexOf = substring.indexOf(45);
|
||
|
String substring2 = substring.substring(0, indexOf);
|
||
|
if (indexOf > 0) {
|
||
|
return loadObject(substring2);
|
||
|
}
|
||
|
return null;
|
||
|
}
|
||
|
|
||
|
private PemObject loadObject(String str) throws IOException {
|
||
|
String readLine;
|
||
|
String concat = END.concat(String.valueOf(str));
|
||
|
StringBuffer stringBuffer = new StringBuffer();
|
||
|
ArrayList arrayList = new ArrayList();
|
||
|
while (true) {
|
||
|
readLine = readLine();
|
||
|
if (readLine != null) {
|
||
|
if (readLine.indexOf(":") < 0) {
|
||
|
if (readLine.indexOf(concat) != -1) {
|
||
|
break;
|
||
|
}
|
||
|
stringBuffer.append(readLine.trim());
|
||
|
} else {
|
||
|
int indexOf = readLine.indexOf(58);
|
||
|
arrayList.add(new PemHeader(readLine.substring(0, indexOf), readLine.substring(indexOf + 1).trim()));
|
||
|
}
|
||
|
} else {
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
if (readLine != null) {
|
||
|
return new PemObject(str, arrayList, Base64.decode(stringBuffer.toString()));
|
||
|
}
|
||
|
StringBuilder sb = new StringBuilder();
|
||
|
sb.append(concat);
|
||
|
sb.append(" not found");
|
||
|
throw new IOException(sb.toString());
|
||
|
}
|
||
|
|
||
|
public PemReader(Reader reader) {
|
||
|
super(reader);
|
||
|
}
|
||
|
}
|