2018-06-13 17:26:48 +02:00
|
|
|
/*
|
|
|
|
* Copyright 2018 Paul Schaub.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
2018-07-18 18:23:06 +02:00
|
|
|
package org.pgpainless.algorithm;
|
2018-06-02 21:21:35 +02:00
|
|
|
|
|
|
|
import java.util.Map;
|
2020-01-09 20:49:12 +01:00
|
|
|
import java.util.concurrent.ConcurrentHashMap;
|
2018-06-02 21:21:35 +02:00
|
|
|
|
|
|
|
import org.bouncycastle.bcpg.CompressionAlgorithmTags;
|
|
|
|
|
2021-04-25 13:28:33 +02:00
|
|
|
/**
|
|
|
|
* Enumeration of possible compression algorithms.
|
|
|
|
*
|
|
|
|
* @see <a href="https://tools.ietf.org/html/rfc4880#section-9.3">RFC4880: Compression Algorithm Tags</a>
|
|
|
|
*/
|
2018-06-02 21:21:35 +02:00
|
|
|
public enum CompressionAlgorithm {
|
|
|
|
|
2018-07-02 21:40:59 +02:00
|
|
|
UNCOMPRESSED (CompressionAlgorithmTags.UNCOMPRESSED),
|
|
|
|
ZIP (CompressionAlgorithmTags.ZIP),
|
|
|
|
ZLIB (CompressionAlgorithmTags.ZLIB),
|
|
|
|
BZIP2 (CompressionAlgorithmTags.BZIP2),
|
2018-06-02 21:21:35 +02:00
|
|
|
;
|
|
|
|
|
2020-01-09 20:49:12 +01:00
|
|
|
private static final Map<Integer, CompressionAlgorithm> MAP = new ConcurrentHashMap<>();
|
2018-06-02 21:21:35 +02:00
|
|
|
|
|
|
|
static {
|
|
|
|
for (CompressionAlgorithm c : CompressionAlgorithm.values()) {
|
|
|
|
MAP.put(c.algorithmId, c);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-25 13:28:33 +02:00
|
|
|
/**
|
|
|
|
* Return the {@link CompressionAlgorithm} value that corresponds to the provided numerical id.
|
|
|
|
* If an invalid id is provided, null is returned.
|
|
|
|
*
|
|
|
|
* @param id id
|
|
|
|
* @return compression algorithm
|
|
|
|
*/
|
2018-06-02 21:21:35 +02:00
|
|
|
public static CompressionAlgorithm fromId(int id) {
|
|
|
|
return MAP.get(id);
|
|
|
|
}
|
|
|
|
|
|
|
|
private final int algorithmId;
|
|
|
|
|
|
|
|
CompressionAlgorithm(int id) {
|
|
|
|
this.algorithmId = id;
|
|
|
|
}
|
|
|
|
|
2021-04-25 13:28:33 +02:00
|
|
|
/**
|
|
|
|
* Return the numerical algorithm tag corresponding to this compression algorithm.
|
|
|
|
* @return id
|
|
|
|
*/
|
2018-06-02 21:21:35 +02:00
|
|
|
public int getAlgorithmId() {
|
|
|
|
return algorithmId;
|
|
|
|
}
|
|
|
|
}
|