Update copyright.
[shibboleth/cpp-xmltooling.git] / xmltooling / security / impl / XSECCryptoX509CRL.cpp
1 /*
2  * Copyright 2001-2007 The Apache Software Foundation.
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  * XSECCryptoX509CRL.cpp
19  * 
20  * Wrapper for X.509 CRL objects, similar to existing XSEC wrappers.
21  */
22
23 #include "internal.h"
24 #include "security/XSECCryptoX509CRL.h"
25
26 #include <xsec/framework/XSECError.hpp>
27 #include <xsec/enc/XSECCryptoException.hpp>
28
29 using namespace xmltooling;
30
31 void XSECCryptoX509CRL::loadX509CRLPEM(const char* buf, unsigned int len)
32 {
33         const char * b;
34         char * b1 = NULL;
35         if (len == 0)
36                 b = buf;
37         else {
38                 XSECnew(b1, char[len+1]);
39                 memcpy(b1, buf, len);
40                 b1[len] = '\0';
41                 b = b1;
42         }
43
44         const char *p = strstr(buf, "-----BEGIN X509 CRL-----");
45
46         if (p == NULL) {
47
48                 if (b1 != NULL)
49                         delete[] b1;
50
51                 throw XSECCryptoException(XSECCryptoException::X509Error,
52                 "X509CRL::loadX509CRLPEM - Cannot find start of PEM CRL");
53
54         }
55
56         p += strlen("-----BEGIN X509 CRL-----");
57
58         while (*p == '\n' || *p == '\r' || *p == '-')
59                 p++;
60
61         safeBuffer output;
62         int i = 0;
63         while (*p != '\0' && *p != '-') {
64                 output[i++] = *p;
65                 ++p;
66         }
67
68         if (strstr(p, "-----END X509 CRL-----") != p) {
69
70                 if (b1 != NULL)
71                         delete[] b1;
72
73                 throw XSECCryptoException(XSECCryptoException::X509Error,
74                 "X509CRL::loadX509PEMCRL - Cannot find end of PEM certificate");
75
76         }
77         
78         if (b1 != NULL)
79                 delete[] b1;
80
81         output[i] = '\0';
82
83         this->loadX509CRLBase64Bin(output.rawCharBuffer(), i);
84
85 }
86