replace : iotivity -> iotivity-sec
[platform/upstream/iotivity.git] / android / android_api / base / src / main / java / org / iotivity / ca / CaTransportFlags.java
1 /* ****************************************************************
2  *
3  * Copyright 2017 Samsung Electronics All Rights Reserved.
4  *
5  *
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  ******************************************************************/
20
21 package org.iotivity.ca;
22
23 import java.util.EnumSet;
24 import java.security.InvalidParameterException;
25
26 public enum CaTransportFlags {
27
28     CA_DEFAULT_FLAGS(0),
29
30     /** Insecure transport is the default (subject to change) */
31     CA_SECURE (1 << 4),   // secure the transport path
32
33     /** IPv4 & IPv6 autoselection is the default */
34     CA_IPV6 (1 << 5),   // IP adapter only
35     CA_IPV4 (1 << 6),   // IP adapter only
36
37     /** Indication that a message was received by multicast. */
38     CA_MULTICAST (1 << 7),
39
40     /** Link-Local multicast is the default multicast scope for IPv6.
41      *These correspond in both value and position to the IPv6 address bits. */
42     CA_SCOPE_INTERFACE (0x1), // IPv6 Interface-Local scope
43     CA_SCOPE_LINK (0x2), // IPv6 Link-Local scope (default)
44     CA_SCOPE_REALM (0x3), // IPv6 Realm-Local scope
45     CA_SCOPE_ADMIN (0x4), // IPv6 Admin-Local scope
46     CA_SCOPE_SITE (0x5), // IPv6 Site-Local scope
47     CA_SCOPE_ORG (0x8), // IPv6 Organization-Local scope
48     CA_SCOPE_GLOBAL (0xE), // IPv6 Global scope
49     ;
50     private int value;
51
52     private CaTransportFlags(int value) {
53         this.value = value;
54     }
55
56     public int getValue() {
57         return this.value;
58     }
59
60     public static EnumSet<CaTransportFlags> convertToEnumSet(int value) {
61
62         EnumSet<CaTransportFlags> typeSet = null;
63         for (CaTransportFlags v : values()) {
64             if (0 != (value & v.getValue())) {
65                 if (null == typeSet) {
66                     typeSet = EnumSet.of(v);
67                 } else {
68                     typeSet.add(v);
69                 }
70             }
71         }
72
73         if (null == typeSet || typeSet.isEmpty()) {
74             throw new InvalidParameterException("Unexpected CaTransportFlag value:" + value);
75         }
76
77         return typeSet;
78     }
79 }