forked from frankframework/frankframework
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Cleanup code in akamai module (frankframework#2317)
- Loading branch information
Showing
68 changed files
with
831 additions
and
507 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
akamai/src/main/java/nl/nn/adapterframework/extensions/akamai/HashAlgorithm.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
/* | ||
Copyright 2021 WeAreFrank! | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
package nl.nn.adapterframework.extensions.akamai; | ||
|
||
import java.io.IOException; | ||
import java.security.MessageDigest; | ||
import java.security.NoSuchAlgorithmException; | ||
|
||
import lombok.Getter; | ||
import nl.nn.adapterframework.stream.Message; | ||
import nl.nn.adapterframework.util.Misc; | ||
|
||
/** | ||
* An enum of the hash algorithms. Currently supported hashes include MD5; SHA1; SHA256 | ||
* | ||
* The string representation matches the java {@link java.security.MessageDigest#getInstance(String)} canonical names. | ||
* | ||
* @author Niels Meijer | ||
*/ | ||
public enum HashAlgorithm { | ||
MD5("MD5"), SHA1("SHA-1"), SHA256("SHA-256"); | ||
|
||
/** | ||
* Algorithm name as defined in {@link java.security.MessageDigest#getInstance(String)} | ||
*/ | ||
private @Getter final String algorithm; | ||
|
||
private HashAlgorithm(final String algorithm) { | ||
this.algorithm = algorithm; | ||
} | ||
|
||
public String computeHash(Message file) throws IOException { | ||
byte[] fileBytes = file.asByteArray(); | ||
if (fileBytes == null) { | ||
throw new IllegalStateException("unable to compute hash over null message"); | ||
} | ||
|
||
byte[] checksum = computeHash(fileBytes, this); | ||
if(checksum != null) { | ||
return Misc.asHex(checksum); | ||
} | ||
|
||
throw new IllegalStateException("error computing checksum"); | ||
} | ||
|
||
/** | ||
* Computes the hash of a given InputStream. This is a wrapper over the MessageDigest crypto functions. | ||
* | ||
* @param srcBytes to generate a hash over | ||
* @param hashAlgorithm the Algorithm to use to compute the hash | ||
* @return a byte[] representation of the hash. If the InputStream is a null object | ||
* then null will be returned. If the InputStream is empty an empty byte[] {} will be returned. | ||
*/ | ||
private static byte[] computeHash(byte[] srcBytes, HashAlgorithm hashAlgorithm) { | ||
try { | ||
MessageDigest digest = MessageDigest.getInstance(hashAlgorithm.getAlgorithm()); | ||
|
||
return digest.digest(srcBytes); | ||
} catch (NoSuchAlgorithmException e) { | ||
//no-op. This will never happen since we are using an enum to limit the hash algorithms | ||
throw new IllegalArgumentException("This should never happen! We are using an enum!", e); | ||
} | ||
} | ||
} |
176 changes: 0 additions & 176 deletions
176
akamai/src/main/java/nl/nn/adapterframework/extensions/akamai/NetStorageAction.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.