blob: 06ab4dc26069ffa8bfea535351d613b562c7c1ec [file] [log] [blame]
[email protected]ce82c0572012-04-16 21:22:191// Copyright (c) 2012 The Chromium Authors. All rights reserved.
license.botbf09a502008-08-24 00:55:552// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
initial.commit09911bf2008-07-26 23:55:294//
5// Utilities for the SafeBrowsing code.
6
[email protected]5da98afc2008-09-20 11:42:497#ifndef CHROME_BROWSER_SAFE_BROWSING_SAFE_BROWSING_UTIL_H_
8#define CHROME_BROWSER_SAFE_BROWSING_SAFE_BROWSING_UTIL_H_
initial.commit09911bf2008-07-26 23:55:299
avib896c712015-12-26 02:10:4310#include <stddef.h>
11
[email protected]1eb867e82009-12-01 23:50:1012#include <cstring>
dcheng7bacc0e2016-04-11 20:10:5413#include <memory>
initial.commit09911bf2008-07-26 23:55:2914#include <string>
15#include <vector>
16
avib896c712015-12-26 02:10:4317#include "base/macros.h"
[email protected]2898118f2014-03-13 10:13:4918#include "base/strings/string_piece.h"
[email protected]9c60c9662014-06-28 05:36:4419#include "base/time/time.h"
initial.commit09911bf2008-07-26 23:55:2920#include "chrome/browser/safe_browsing/chunk_range.h"
Tim Volodinee45938472017-09-21 10:08:2221#include "components/safe_browsing/db/util.h"
[email protected]46072d42008-07-28 14:49:3522
[email protected]d2b383a2014-06-11 07:11:5923namespace safe_browsing {
vakh9a474d832015-11-13 01:43:0924
[email protected]d2b383a2014-06-11 07:11:5925class ChunkData;
initial.commit09911bf2008-07-26 23:55:2926
[email protected]ce82c0572012-04-16 21:22:1927// Container for holding a chunk URL and the list it belongs to.
[email protected]961354e2009-12-01 21:09:5428struct ChunkUrl {
29 std::string url;
[email protected]961354e2009-12-01 21:09:5430 std::string list_name;
31};
32
[email protected]d2b383a2014-06-11 07:11:5933// Data for an individual chunk sent from the server.
34class SBChunkData {
[email protected]7b1e37102010-03-08 21:43:1635 public:
[email protected]d2b383a2014-06-11 07:11:5936 SBChunkData();
37 ~SBChunkData();
[email protected]7b1e37102010-03-08 21:43:1638
[email protected]d2b383a2014-06-11 07:11:5939 // Create with manufactured data, for testing only.
40 // TODO(shess): Right now the test code calling this is in an anonymous
41 // namespace. Figure out how to shift this into private:.
dcheng7bacc0e2016-04-11 20:10:5442 explicit SBChunkData(std::unique_ptr<ChunkData> data);
[email protected]7b1e37102010-03-08 21:43:1643
[email protected]d2b383a2014-06-11 07:11:5944 // Read serialized ChunkData, returning true if the parse suceeded.
45 bool ParseFrom(const unsigned char* data, size_t length);
[email protected]7b1e37102010-03-08 21:43:1646
[email protected]d2b383a2014-06-11 07:11:5947 // Access the chunk data. |AddChunkNumberAt()| can only be called if
48 // |IsSub()| returns true. |Prefix*()| and |FullHash*()| can only be called
49 // if the corrosponding |Is*()| returned true.
50 int ChunkNumber() const;
51 bool IsAdd() const;
52 bool IsSub() const;
53 int AddChunkNumberAt(size_t i) const;
54 bool IsPrefix() const;
55 size_t PrefixCount() const;
56 SBPrefix PrefixAt(size_t i) const;
57 bool IsFullHash() const;
58 size_t FullHashCount() const;
59 SBFullHash FullHashAt(size_t i) const;
[email protected]7b1e37102010-03-08 21:43:1660
61 private:
[email protected]d2b383a2014-06-11 07:11:5962 // Protocol buffer sent from server.
dcheng7bacc0e2016-04-11 20:10:5463 std::unique_ptr<ChunkData> chunk_data_;
[email protected]7b1e37102010-03-08 21:43:1664
[email protected]d2b383a2014-06-11 07:11:5965 DISALLOW_COPY_AND_ASSIGN(SBChunkData);
[email protected]7b1e37102010-03-08 21:43:1666};
67
initial.commit09911bf2008-07-26 23:55:2968// Contains information about a list in the database.
69struct SBListChunkRanges {
[email protected]93aa89c72010-10-20 21:32:0470 explicit SBListChunkRanges(const std::string& n);
71
initial.commit09911bf2008-07-26 23:55:2972 std::string name; // The list name.
73 std::string adds; // The ranges for add chunks.
74 std::string subs; // The ranges for sub chunks.
initial.commit09911bf2008-07-26 23:55:2975};
76
77// Container for deleting chunks from the database.
78struct SBChunkDelete {
[email protected]93aa89c72010-10-20 21:32:0479 SBChunkDelete();
vmpstrb8aacbe2016-02-26 02:00:4880 SBChunkDelete(const SBChunkDelete& other);
[email protected]93aa89c72010-10-20 21:32:0481 ~SBChunkDelete();
82
initial.commit09911bf2008-07-26 23:55:2983 std::string list_name;
84 bool is_sub_del;
85 std::vector<ChunkRange> chunk_del;
86};
87
vakh9a474d832015-11-13 01:43:0988} // namespace safe_browsing
89
[email protected]5da98afc2008-09-20 11:42:4990#endif // CHROME_BROWSER_SAFE_BROWSING_SAFE_BROWSING_UTIL_H_