Upstream version 11.40.277.0
[platform/framework/web/crosswalk.git] / src / net / cert / x509_util_openssl.h
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef NET_CERT_X509_UTIL_OPENSSL_H_
6 #define NET_CERT_X509_UTIL_OPENSSL_H_
7
8 #include <openssl/asn1.h>
9 #include <openssl/x509v3.h>
10
11 #include <string>
12 #include <vector>
13
14 #include "base/strings/string_piece.h"
15 #include "net/base/net_export.h"
16
17 namespace base {
18 class Time;
19 }  // namespace base
20
21 namespace net {
22
23 // A collection of helper functions to fetch data from OpenSSL X509 certificates
24 // into more convenient std / base datatypes.
25 namespace x509_util {
26
27 bool NET_EXPORT ParsePrincipalKeyAndValue(X509_NAME_ENTRY* entry,
28                                           std::string* key,
29                                           std::string* value);
30
31 bool NET_EXPORT ParsePrincipalKeyAndValueByIndex(X509_NAME* name,
32                                                  int index,
33                                                  std::string* key,
34                                                  std::string* value);
35
36 bool NET_EXPORT ParsePrincipalValueByIndex(X509_NAME* name,
37                                            int index,
38                                            std::string* value);
39
40 bool NET_EXPORT ParsePrincipalValueByNID(X509_NAME* name,
41                                          int nid,
42                                          std::string* value);
43
44 bool NET_EXPORT ParseDate(ASN1_TIME* x509_time, base::Time* time);
45
46 // DER-encodes |x509|, caching the encoding in a structure owned by
47 // the X509. On success, returns true, and sets |*out_der| to point to
48 // the encoding. The StringPiece is valid as long as |x509| is not
49 // freed.
50 //
51 // Note: this caches the encoding, so |x509| must not be modified
52 // after the first call to this function.
53 bool NET_EXPORT GetDER(X509* x509, base::StringPiece* out_der);
54
55 } // namespace x509_util
56
57 } // namespace net
58
59 #endif  // NET_CERT_X509_UTIL_OPENSSL_H_