Skip to content

Commit

Permalink
Merge pull request #72 from varmenise/CJP-5848
Browse files Browse the repository at this point in the history
[JENKINS-39381] add API method which allows to check if a given string is of type ByteSecrets
  • Loading branch information
stephenc committed Nov 9, 2016
2 parents 6b6632c + 12746bc commit 5086577
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/main/java/com/cloudbees/plugins/credentials/SecretBytes.java
Expand Up @@ -289,6 +289,21 @@ public static SecretBytes fromString(String data) {
return s;
}

/**
* check if the given String is a SecretBytes text by attempting to decrypt it
* @param data the string to check
* @return true if the decryption was successful, false otherwise
*/
public static boolean iSecretBytes(String data) {
data = Util.fixNull(data);
int len = data.length();
if (len >= 2 && ENCRYPTED_VALUE_PATTERN.matcher(data).matches()) {
byte[] decoded = Base64.decode(data.substring(1, len - 1));
return decrypt(decoded) != null;
}
return false;
}

/**
* {@inheritDoc}
*/
Expand Down

0 comments on commit 5086577

Please sign in to comment.