blob: 94972a2de4e07fb973758d9798f568233e419d78 (
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
|
// Copyright (c) 2012 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.
//
// Utilities for the SafeBrowsing code.
#ifndef CHROME_BROWSER_SAFE_BROWSING_SAFE_BROWSING_UTIL_H_
#define CHROME_BROWSER_SAFE_BROWSING_SAFE_BROWSING_UTIL_H_
#include <cstring>
#include <string>
#include <vector>
#include "base/basictypes.h"
#include "base/memory/scoped_ptr.h"
#include "base/strings/string_piece.h"
#include "base/time/time.h"
#include "chrome/browser/safe_browsing/chunk_range.h"
#include "components/safe_browsing_db/util.h"
namespace safe_browsing {
class ChunkData;
// Container for holding a chunk URL and the list it belongs to.
struct ChunkUrl {
std::string url;
std::string list_name;
};
// Data for an individual chunk sent from the server.
class SBChunkData {
public:
SBChunkData();
~SBChunkData();
// Create with manufactured data, for testing only.
// TODO(shess): Right now the test code calling this is in an anonymous
// namespace. Figure out how to shift this into private:.
explicit SBChunkData(scoped_ptr<ChunkData> data);
// Read serialized ChunkData, returning true if the parse suceeded.
bool ParseFrom(const unsigned char* data, size_t length);
// Access the chunk data. |AddChunkNumberAt()| can only be called if
// |IsSub()| returns true. |Prefix*()| and |FullHash*()| can only be called
// if the corrosponding |Is*()| returned true.
int ChunkNumber() const;
bool IsAdd() const;
bool IsSub() const;
int AddChunkNumberAt(size_t i) const;
bool IsPrefix() const;
size_t PrefixCount() const;
SBPrefix PrefixAt(size_t i) const;
bool IsFullHash() const;
size_t FullHashCount() const;
SBFullHash FullHashAt(size_t i) const;
private:
// Protocol buffer sent from server.
scoped_ptr<ChunkData> chunk_data_;
DISALLOW_COPY_AND_ASSIGN(SBChunkData);
};
// Contains information about a list in the database.
struct SBListChunkRanges {
explicit SBListChunkRanges(const std::string& n);
std::string name; // The list name.
std::string adds; // The ranges for add chunks.
std::string subs; // The ranges for sub chunks.
};
// Container for deleting chunks from the database.
struct SBChunkDelete {
SBChunkDelete();
~SBChunkDelete();
std::string list_name;
bool is_sub_del;
std::vector<ChunkRange> chunk_del;
};
} // namespace safe_browsing
#endif // CHROME_BROWSER_SAFE_BROWSING_SAFE_BROWSING_UTIL_H_
|