blob: 2bd3df98d250dff3f0fb01c6c11b714b99d8621d [file] [log] [blame]
Jian Lif8c2d4a2016-09-15 02:33:12 +09001/*
2 * Copyright 2016-present Open Networking Laboratory
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16package org.onosproject.lisp.msg.authentication;
17
18/**
19 * Authentication key enumeration class.
20 *
21 * By far, LISP also support two types of MAC authentication which are
22 * HMAC-SHA-1-96 and HMAC-SHA-256-128.
23 *
24 * https://tools.ietf.org/html/rfc6830#page-39
25 */
26public enum LispAuthenticationKeyEnum {
27
28 /** No authentication. */
Jian Li51aaca12016-11-11 01:56:15 +090029 NONE(0, null, 0),
Jian Lif8c2d4a2016-09-15 02:33:12 +090030
31 /** HMAC SHA1 encryption. */
Jian Li51aaca12016-11-11 01:56:15 +090032 SHA1(1, "HmacSHA1", 20),
Jian Lif8c2d4a2016-09-15 02:33:12 +090033
34 /** HMAC SHA256 encryption. */
Jian Li51aaca12016-11-11 01:56:15 +090035 SHA256(2, "HmacSHA256", 32),
Jian Lif8c2d4a2016-09-15 02:33:12 +090036
37 /** Unsupported authentication type. */
Jian Li51aaca12016-11-11 01:56:15 +090038 UNKNOWN(-1, "UNKNOWN", 0);
Jian Lif8c2d4a2016-09-15 02:33:12 +090039
40 private short keyId;
41 private String name;
Jian Li51aaca12016-11-11 01:56:15 +090042 private short length;
Jian Lif8c2d4a2016-09-15 02:33:12 +090043
Jian Li51aaca12016-11-11 01:56:15 +090044 LispAuthenticationKeyEnum(int keyId, String name, int length) {
Jian Lif8c2d4a2016-09-15 02:33:12 +090045 this.keyId = (short) keyId;
46 this.name = name;
Jian Li51aaca12016-11-11 01:56:15 +090047 this.length = (short) length;
Jian Lif8c2d4a2016-09-15 02:33:12 +090048 }
49
50 /**
51 * Obtains authentication key identifier.
52 *
53 * @return authentication key identifier
54 */
55 public short getKeyId() {
56 return keyId;
57 }
58
59 /**
60 * Obtains authentication name.
61 *
62 * @return authentication name
63 */
64 public String getName() {
65 return name;
66 }
67
68 /**
Jian Li51aaca12016-11-11 01:56:15 +090069 * Obtains hash length.
70 *
71 * @return hash length
72 */
73 public short getHashLength() {
74 return length;
75 }
76
77 /**
Jian Lif8c2d4a2016-09-15 02:33:12 +090078 * Obtains LISP authentication key enum by providing key identifier.
79 *
80 * @param keyId LISP authentication key identifier
81 * @return LISP authentication key enum
82 */
83 public static LispAuthenticationKeyEnum valueOf(short keyId) {
84 for (LispAuthenticationKeyEnum val : values()) {
85 if (val.getKeyId() == keyId) {
86 return val;
87 }
88 }
89 return UNKNOWN;
90 }
91}