update the latest source
[platform/core/connectivity/smartcard-service.git] / common / PKCS15OID.cpp
1 /*
2 * Copyright (c) 2012 Samsung Electronics Co., Ltd All Rights Reserved
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
18 /* standard library header */
19
20 /* SLP library header */
21
22 /* local header */
23 #include "Debug.h"
24 #include "PKCS15.h"
25 #include "PKCS15OID.h"
26 #include "SimpleTLV.h"
27
28 namespace smartcard_service_api
29 {
30         PKCS15OID::PKCS15OID(ByteArray data)
31         {
32                 parseOID(data);
33         }
34
35         PKCS15OID::~PKCS15OID()
36         {
37         }
38
39         bool PKCS15OID::parseOID(ByteArray data)
40         {
41                 bool result = false;
42                 SimpleTLV tlv(data);
43
44                 SCARD_BEGIN();
45
46                 while (tlv.decodeTLV() == true)
47                 {
48                         switch (tlv.getTag())
49                         {
50                         case PKCS15::TAG_SEQUENCE :
51                                 if (tlv.getLength() > 0)
52                                 {
53                                         /* common object attribute */
54                                         tlv.enterToValueTLV();
55                                         if (tlv.decodeTLV() == true && tlv.getTag() == 0x0C) /* ?? */
56                                         {
57                                                 name = tlv.getValue();
58                                                 SCARD_DEBUG("name : %s", name.toString());
59                                         }
60                                         tlv.returnToParentTLV();
61                                 }
62                                 else
63                                 {
64                                         /* common object attribute */
65                                         /* if you want to use this value, add member variable and parse here */
66 //                                      SCARD_DEBUG_ERR("common object attribute is empty");
67                                 }
68                                 break;
69
70                         case 0xA0 : /* CHOICE 0 : External Oid??? */
71                                 SCARD_DEBUG_ERR("oid doesn't exist");
72                                 break;
73
74                         case 0xA1 : /* CHOICE 1 : OidDO */
75                                 tlv.enterToValueTLV();
76
77                                 /* attribute */
78                                 if (tlv.decodeTLV() == true && tlv.getTag() == PKCS15::TAG_SEQUENCE)
79                                 {
80                                         tlv.enterToValueTLV();
81
82                                         /* oid */
83                                         if (tlv.decodeTLV() == true && tlv.getTag() == (unsigned int)0x06) /* ?? */
84                                         {
85                                                 oid = tlv.getValue();
86
87                                                 SCARD_DEBUG("oid : %s", oid.toString());
88                                         }
89                                         else
90                                         {
91                                                 SCARD_DEBUG_ERR("oid is empty");
92                                         }
93
94                                         /* path */
95                                         if (tlv.decodeTLV() == true && tlv.getTag() == PKCS15::TAG_SEQUENCE)
96                                         {
97                                                 path = SimpleTLV::getOctetString(tlv.getValue());
98
99                                                 SCARD_DEBUG("path : %s", path.toString());
100
101                                                 result = true;
102                                         }
103                                         else
104                                         {
105                                                 SCARD_DEBUG_ERR("sequence is empty");
106                                         }
107
108                                         tlv.returnToParentTLV();
109                                 }
110                                 else
111                                 {
112                                         SCARD_DEBUG_ERR("common dataobject attribute is empty");
113                                 }
114                                 tlv.returnToParentTLV();
115
116                                 break;
117
118                         default :
119                                 SCARD_DEBUG_ERR("Unknown tag : 0x%02X", tlv.getTag());
120                                 break;
121                         }
122                 }
123
124                 SCARD_END();
125
126                 return result;
127         }
128
129         ByteArray PKCS15OID::getOID()
130         {
131                 return oid;
132         }
133
134         ByteArray PKCS15OID::getName()
135         {
136                 return name;
137         }
138
139         ByteArray PKCS15OID::getPath()
140         {
141                 return path;
142         }
143
144 } /* namespace smartcard_service_api */