blob: ecf6c8e663d98050ea3ce4e48b8d6d4ae09ce010 [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. */
29 NONE(0, null),
30
31 /** HMAC SHA1 encryption. */
32 SHA1(1, "HmacSHA1"),
33
34 /** HMAC SHA256 encryption. */
35 SHA256(2, "HmacSHA256"),
36
37 /** Unsupported authentication type. */
38 UNKNOWN(-1, "UNKNOWN");
39
40 private short keyId;
41 private String name;
42
43 LispAuthenticationKeyEnum(int keyId, String name) {
44 this.keyId = (short) keyId;
45 this.name = name;
46 }
47
48 /**
49 * Obtains authentication key identifier.
50 *
51 * @return authentication key identifier
52 */
53 public short getKeyId() {
54 return keyId;
55 }
56
57 /**
58 * Obtains authentication name.
59 *
60 * @return authentication name
61 */
62 public String getName() {
63 return name;
64 }
65
66 /**
67 * Obtains LISP authentication key enum by providing key identifier.
68 *
69 * @param keyId LISP authentication key identifier
70 * @return LISP authentication key enum
71 */
72 public static LispAuthenticationKeyEnum valueOf(short keyId) {
73 for (LispAuthenticationKeyEnum val : values()) {
74 if (val.getKeyId() == keyId) {
75 return val;
76 }
77 }
78 return UNKNOWN;
79 }
80}