Skip to content

Commit

Permalink
[JENKINS-39381] add API method which allows to check if a given strin…
Browse files Browse the repository at this point in the history
…g is of type ByteSecrets
  • Loading branch information
varmenise committed Nov 9, 2016
1 parent 6b6632c commit 12746bc
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 12746bc

Please sign in to comment.