Apply coding rule
[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                                         /* common object attribute */
52                                         tlv.enterToValueTLV();
53                                         if (tlv.decodeTLV() == true && tlv.getTag() == 0x0C) /* ?? */ {
54                                                 name = tlv.getValue();
55                                                 SECURE_LOGD("name : %s", name.toString().c_str());
56                                         }
57                                         tlv.returnToParentTLV();
58                                 } else {
59                                         /* common object attribute */
60                                         /* if you want to use this value, add member variable and parse here */
61 //                                      _ERR("common object attribute is empty");
62                                 }
63                                 break;
64
65                         case 0xA0 : /* CHOICE 0 : External Oid??? */
66                                 _ERR("oid doesn't exist");
67                                 break;
68
69                         case 0xA1 : /* CHOICE 1 : OidDO */
70                                 tlv.enterToValueTLV();
71
72                                 /* attribute */
73                                 if (tlv.decodeTLV() == true && tlv.getTag() == PKCS15::TAG_SEQUENCE) {
74                                         tlv.enterToValueTLV();
75
76                                         /* oid */
77                                         if (tlv.decodeTLV() == true && tlv.getTag() == (unsigned int)0x06) /* ?? */ {
78                                                 oid = tlv.getValue();
79
80                                                 _DBG("oid : %s", oid.toString().c_str());
81                                         } else {
82                                                 _ERR("oid is empty");
83                                         }
84
85                                         /* path */
86                                         if (tlv.decodeTLV() == true && tlv.getTag() == PKCS15::TAG_SEQUENCE) {
87                                                 path = SimpleTLV::getOctetString(tlv.getValue());
88
89                                                 _DBG("path : %s", path.toString().c_str());
90
91                                                 result = true;
92                                         } else {
93                                                 _ERR("sequence is empty");
94                                         }
95
96                                         tlv.returnToParentTLV();
97                                 } else {
98                                         _ERR("common dataobject attribute is empty");
99                                 }
100                                 tlv.returnToParentTLV();
101
102                                 break;
103
104                         default :
105                                 _ERR("Unknown tag : 0x%02X", tlv.getTag());
106                                 break;
107                         }
108                 }
109
110                 _END();
111
112                 return result;
113         }
114 } /* namespace smartcard_service_api */