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