0c8eea807090f4a1d5b26429d94a3bb63572103d
[shibboleth/cpp-xmltooling.git] / xmltooling / security / impl / XSECCryptoX509CRL.cpp
1 /*\r
2  * Copyright 2006 The Apache Software Foundation.\r
3  *\r
4  * Licensed under the Apache License, Version 2.0 (the "License");\r
5  * you may not use this file except in compliance with the License.\r
6  * You may obtain a copy of the License at\r
7  *\r
8  *     http://www.apache.org/licenses/LICENSE-2.0\r
9  *\r
10  * Unless required by applicable law or agreed to in writing, software\r
11  * distributed under the License is distributed on an "AS IS" BASIS,\r
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
13  * See the License for the specific language governing permissions and\r
14  * limitations under the License.\r
15  */\r
16 \r
17 /**\r
18  * XSECCryptoX509CRL.cpp\r
19  * \r
20  * Wrapper for X.509 CRL objects, similar to existing XSEC wrappers.\r
21  */\r
22 \r
23 #include "internal.h"\r
24 #include "security/XSECCryptoX509CRL.h"\r
25 \r
26 #include <xsec/framework/XSECError.hpp>\r
27 #include <xsec/enc/XSECCryptoException.hpp>\r
28 \r
29 using namespace xmltooling;\r
30 \r
31 void XSECCryptoX509CRL::loadX509CRLPEM(const char* buf, unsigned int len)\r
32 {\r
33         const char * b;\r
34         char * b1 = NULL;\r
35         if (len == 0)\r
36                 b = buf;\r
37         else {\r
38                 XSECnew(b1, char[len+1]);\r
39                 memcpy(b1, buf, len);\r
40                 b1[len] = '\0';\r
41                 b = b1;\r
42         }\r
43 \r
44         const char *p = strstr(buf, "-----BEGIN X509 CRL-----");\r
45 \r
46         if (p == NULL) {\r
47 \r
48                 if (b1 != NULL)\r
49                         delete[] b1;\r
50 \r
51                 throw XSECCryptoException(XSECCryptoException::X509Error,\r
52                 "X509CRL::loadX509CRLPEM - Cannot find start of PEM CRL");\r
53 \r
54         }\r
55 \r
56         p += strlen("-----BEGIN X509 CRL-----");\r
57 \r
58         while (*p == '\n' || *p == '\r' || *p == '-')\r
59                 p++;\r
60 \r
61         safeBuffer output;\r
62         int i = 0;\r
63         while (*p != '\0' && *p != '-') {\r
64                 output[i++] = *p;\r
65                 ++p;\r
66         }\r
67 \r
68         if (strstr(p, "-----END X509 CRL-----") != p) {\r
69 \r
70                 if (b1 != NULL)\r
71                         delete[] b1;\r
72 \r
73                 throw XSECCryptoException(XSECCryptoException::X509Error,\r
74                 "X509CRL::loadX509PEMCRL - Cannot find end of PEM certificate");\r
75 \r
76         }\r
77         \r
78         if (b1 != NULL)\r
79                 delete[] b1;\r
80 \r
81         output[i] = '\0';\r
82 \r
83         this->loadX509CRLBase64Bin(output.rawCharBuffer(), i);\r
84 \r
85 }\r
86 \r