summaryrefslogtreecommitdiffstats
path: root/net/cert/crl_set_storage.h
blob: dd15796aa5be5daa0ac2b4e22b874d210f42607a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef NET_CERT_CRL_SET_STORAGE_H_
#define NET_CERT_CRL_SET_STORAGE_H_

#include <string>
#include <utility>
#include <vector>

#include "base/strings/string_piece.h"
#include "net/base/net_export.h"
#include "net/cert/crl_set.h"

namespace base {
class DictionaryValue;
}

namespace net {

// Static helpers to save and load CRLSet.
class NET_EXPORT CRLSetStorage {
 public:
  // Parse parses the bytes in |data| and, on success, puts a new CRLSet in
  // |out_crl_set| and returns true.
  static bool Parse(base::StringPiece data,
                    scoped_refptr<CRLSet>* out_crl_set);

  // ApplyDelta returns a new CRLSet in |out_crl_set| that is the result of
  // updating |in_crl_set| with the delta information in |delta_bytes|.
  static bool ApplyDelta(const CRLSet* in_crl_set,
                         const base::StringPiece& delta_bytes,
                         scoped_refptr<CRLSet>* out_crl_set);

  // GetIsDeltaUpdate extracts the header from |bytes|, sets *is_delta to
  // whether |bytes| is a delta CRL set or not and returns true. In the event
  // of a parse error, it returns false.
  static bool GetIsDeltaUpdate(const base::StringPiece& bytes, bool *is_delta);

  // Serialize returns a string of bytes suitable for passing to Parse. Parsing
  // and serializing a CRLSet is a lossless operation - the resulting bytes
  // will be equal.
  static std::string Serialize(const CRLSet* crl_set);

 private:
  // CopyBlockedSPKIsFromHeader sets |blocked_spkis_| to the list of values
  // from "BlockedSPKIs" in |header_dict|.
  static bool CopyBlockedSPKIsFromHeader(CRLSet* crl_set,
                                         base::DictionaryValue* header_dict);
};

}  // namespace net

#endif  // NET_CERT_CRL_SET_STORAGE_H_