Skip to content

Commit

Permalink
[JENKINS-45553] - Cache the Mac so we do not need to constantly recre…
Browse files Browse the repository at this point in the history
…ate it (#2948)

[JENKINS-45553] - Cache the Mac so we do not need to constantly recreate it
  • Loading branch information
jglick authored and oleg-nenashev committed Jul 30, 2017
1 parent 378199f commit 564ca0b
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions core/src/main/java/jenkins/security/HMACConfidentialKey.java
Expand Up @@ -27,6 +27,7 @@
*/
public class HMACConfidentialKey extends ConfidentialKey {
private volatile SecretKey key;
private Mac mac;
private final int length;

/**
Expand Down Expand Up @@ -61,12 +62,14 @@ public HMACConfidentialKey(Class owner, String shortName) {
this(owner,shortName,Integer.MAX_VALUE);
}


/**
* Computes the message authentication code for the specified byte sequence.
*/
public byte[] mac(byte[] message) {
return chop(createMac().doFinal(message));
public synchronized byte[] mac(byte[] message) {
if (mac == null) {
mac = createMac();
}
return chop(mac.doFinal(message));
}

/**
Expand Down

0 comments on commit 564ca0b

Please sign in to comment.