com.authlete.cose.constants.COSEHeaderParameters Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of cbor Show documentation
Show all versions of cbor Show documentation
A Java library for CBOR, COSE, CWT and mdoc.
The newest version!
/*
* Copyright (C) 2023 Authlete, Inc.
*
* 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
*
* https://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 com.authlete.cose.constants;
import java.util.LinkedHashMap;
import java.util.Map;
/**
* COSE Header Parameters
*
*
*
*
*
* Name
* Label
* Value Type
* Description
* Reference
*
*
*
* {@link #ALG alg}
* 1
* int / tstr
* Cryptographic algorithm to use
* RFC 9052
*
*
*
* {@link #CRIT crit}
* 2
* [+ label]
* Critical headers to be understood
* RFC 9052
*
*
*
* {@link #CONTENT_TYPE content type}
* 3
* tstr / uint
* Content type of the payload
* RFC 9052
*
*
*
* {@link #KID kid}
* 4
* bstr
* Key identifier
* RFC 9052
*
*
*
* {@link #IV IV}
* 5
* bstr
* Full Initialization Vector
* RFC 9052
*
*
*
* {@link #PARTIAL_IV Partial IV}
* 6
* bstr
* Partial Initialization Vector
* RFC 9052
*
*
*
* {@link #X5CHAIN x5chain}
* 33
* COSE_X509
* An ordered chain of X.509 certificates
* RFC 9360
*
*
*
*
*
* @since 1.1
*
* @see IANA: COSE Header Parameters
*/
public final class COSEHeaderParameters
{
/**
* alg (1)
*/
public static final int ALG = 1;
/**
* crit (2)
*/
public static final int CRIT = 2;
/**
* content type (3)
*/
public static final int CONTENT_TYPE = 3;
/**
* kid (4)
*/
public static final int KID = 4;
/**
* IV (5)
*/
public static final int IV = 5;
/**
* Partial IV (6)
*/
public static final int PARTIAL_IV = 6;
/**
* x5chain (33)
*
* @see RFC 9360 CBOR Object Signing and Encryption (COSE): Header Parameters for Carrying and Referencing X.509 Certificates
*
* @since 1.2
*/
public static final int X5CHAIN = 33;
private static final int[] values = {
ALG, CRIT, CONTENT_TYPE, KID, IV, PARTIAL_IV, X5CHAIN,
};
private static final String[] names = {
"alg", "crit", "content type", "kid", "IV", "Partial IV", "x5chain",
};
private static final Map valueToNameMap = createValueToNameMap();
private static Map createValueToNameMap()
{
Map map = new LinkedHashMap<>();
for (int i = 0; i < values.length; i++)
{
map.put(values[i], names[i]);
}
return map;
}
/**
* Get the name of the header parameter to which the integer identifier
* has been assigned to.
*
* @param value
* An integer identifier assigned to a header parameter.
*
* @return
* The name of the header parameter to which the integer identifier
* has been assigned to. If the given identifier is not recognized,
* {@code null} is returned.
*
* @since 1.5
*/
public static String getNameByValue(int value)
{
return valueToNameMap.getOrDefault(value, null);
}
private COSEHeaderParameters()
{
}
}