Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[JENKINS-51965] Removing JAXB dependency #11

Merged
merged 1 commit into from Jun 26, 2018
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

@@ -30,6 +30,7 @@

<properties>
<jenkins.version>2.16</jenkins.version>
<java.level>8</java.level>
</properties>

<dependencies>
@@ -17,11 +17,11 @@
import java.security.spec.PKCS8EncodedKeySpec;
import java.security.spec.RSAPrivateCrtKeySpec;
import java.security.spec.RSAPublicKeySpec;
import java.util.Base64;
import java.util.logging.Level;
import java.util.logging.Logger;

import javax.annotation.Nonnull;
import javax.xml.bind.DatatypeConverter;

import org.apache.commons.lang.StringUtils;
import org.kohsuke.accmod.Restricted;
@@ -124,10 +124,8 @@ public static String encodePEM(@Nonnull KeyPair keys) throws IOException {
}

private static byte[] extractBinaryPEM(String pem, String header, String footer) {
String stripedPEM = StringUtils.stripEnd(StringUtils.strip(pem, header), header);
// sanity cleanup
stripedPEM = stripedPEM.replaceAll("(\r|\n|\t| )", "");
return DatatypeConverter.parseBase64Binary(stripedPEM);
String stripedPEM = StringUtils.stripEnd(StringUtils.strip(pem.trim(), header), footer);
return Base64.getMimeDecoder().decode(stripedPEM);
}

/**
@@ -185,7 +183,9 @@ private static RSAPrivateCrtKeySpec newRSAPrivateCrtKeySpec(byte[] keyInPkcs1) t

private static void writeEncoded(byte[] bytes, BufferedWriter wr) throws IOException {
char[] buf = new char[PEM_LINE_LENGTH];
bytes = DatatypeConverter.printBase64Binary(bytes).getBytes("UTF-8");
bytes = Base64.getEncoder().encode(bytes);
// getMimeEncoder() may or may not put the NL in the end, which is inconvenient because
// we want to always print NL at the end
for (int i = 0; i < bytes.length; i += buf.length) {
int index;
for (index = 0; index < buf.length && (i + index) < bytes.length; index++) {
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.