Package software.amazon.awssdk.crt.utils
Class PemUtils
java.lang.Object
software.amazon.awssdk.crt.utils.PemUtils
Utility Class used for Cleaning Up and Sanity Checking PEM formatted Strings
for Validity.
-
Method Summary
Modifier and TypeMethodDescriptionstatic StringcleanUpPem(String pem) Cleanup Function that removes most formatting and copy/paste mistakes from PEM formatted Strings.static StringRemoves characters that are not valid in PEM format (non-base64 chars).static booleansafeSanityCheck(String pem, int maxChainLength, String expectedPemTypeSubString) Returns false if there is a problem with a PEM instead of throwing an Exception.static voidsanityCheck(String pem, int maxChainLength, String expectedPemTypeSubString) Performs various sanity checks on a PEM Formatted String, and should be tolerant of common minor mistakes in formatting.
-
Method Details
-
removeInvalidPemChars
Removes characters that are not valid in PEM format (non-base64 chars). No other cleanup is done.- Parameters:
pem- The input "dirty" PEM- Returns:
- The output "clean" PEM
-
cleanUpPem
Cleanup Function that removes most formatting and copy/paste mistakes from PEM formatted Strings.- Parameters:
pem- The input "dirty" PEM- Returns:
- The output "clean" PEM
-
sanityCheck
Performs various sanity checks on a PEM Formatted String, and should be tolerant of common minor mistakes in formatting.- Parameters:
pem- The PEM or PEM Chain to validate.maxChainLength- The max number of PEM encoded objects in the String.expectedPemTypeSubString- A Substring that is expected to be present in the PEM Type.- Throws:
IllegalArgumentException- if there is a problem with the PEM formatted String.
-
safeSanityCheck
public static boolean safeSanityCheck(String pem, int maxChainLength, String expectedPemTypeSubString) Returns false if there is a problem with a PEM instead of throwing an Exception.- Parameters:
pem- The PEM to sanity check.maxChainLength- The Max number of PEM Objects in the PEM StringexpectedPemTypeSubString- A Substring that is expected to be present in the PEM Type.- Returns:
- True if the PEM passes all sanity Checks, false otherwise.
-