Add rule for 'All devices apps' when access rule is empty.
[platform/core/connectivity/smartcard-service.git] / common / PKCS15OID.cpp
1 /*
2  * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
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  */
16
17 #include "Debug.h"
18 #include "PKCS15.h"
19 #include "PKCS15OID.h"
20 #include "SimpleTLV.h"
21
22 namespace smartcard_service_api
23 {
24         PKCS15OID::PKCS15OID(const ByteArray &data)
25         {
26                 parseOID(data);
27         }
28
29         PKCS15OID::~PKCS15OID()
30         {
31         }
32
33         bool PKCS15OID::parseOID(const ByteArray &data)
34         {
35                 bool result = false;
36                 SimpleTLV tlv(data);
37
38                 _BEGIN();
39
40                 while (tlv.decodeTLV() == true)
41                 {
42                         switch (tlv.getTag())
43                         {
44                         case PKCS15::TAG_SEQUENCE :
45                                 if (tlv.size() > 0)
46                                 {
47                                         /* common object attribute */
48                                         tlv.enterToValueTLV();
49                                         if (tlv.decodeTLV() == true && tlv.getTag() == 0x0C) /* ?? */
50                                         {
51                                                 name = tlv.getValue();
52                                         }
53                                         tlv.returnToParentTLV();
54                                 }
55                                 else
56                                 {
57                                         /* common object attribute */
58                                         /* if you want to use this value, add member variable and parse here */
59 //                                      _ERR("common object attribute is empty");
60                                 }
61                                 break;
62
63                         case 0xA0 : /* CHOICE 0 : External Oid??? */
64                                 _ERR("oid doesn't exist");
65                                 break;
66
67                         case 0xA1 : /* CHOICE 1 : OidDO */
68                                 tlv.enterToValueTLV();
69
70                                 /* attribute */
71                                 if (tlv.decodeTLV() == true && tlv.getTag() == PKCS15::TAG_SEQUENCE)
72                                 {
73                                         tlv.enterToValueTLV();
74
75                                         /* oid */
76                                         if (tlv.decodeTLV() == true && tlv.getTag() == (unsigned int)0x06) /* ?? */
77                                         {
78                                                 oid = tlv.getValue();
79
80                                                 _DBG("oid : %s", oid.toString().c_str());
81                                         }
82                                         else
83                                         {
84                                                 _ERR("oid is empty");
85                                         }
86
87                                         /* path */
88                                         if (tlv.decodeTLV() == true && tlv.getTag() == PKCS15::TAG_SEQUENCE)
89                                         {
90                                                 path = SimpleTLV::getOctetString(tlv.getValue());
91
92                                                 _DBG("path : %s", path.toString().c_str());
93
94                                                 result = true;
95                                         }
96                                         else
97                                         {
98                                                 _ERR("sequence is empty");
99                                         }
100
101                                         tlv.returnToParentTLV();
102                                 }
103                                 else
104                                 {
105                                         _ERR("common dataobject attribute is empty");
106                                 }
107                                 tlv.returnToParentTLV();
108
109                                 break;
110
111                         default :
112                                 _ERR("Unknown tag : 0x%02X", tlv.getTag());
113                                 break;
114                         }
115                 }
116
117                 _END();
118
119                 return result;
120         }
121 } /* namespace smartcard_service_api */