proxygen
Utils.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2018-present, Facebook, Inc.
3  * All rights reserved.
4  *
5  * This source code is licensed under the BSD-style license found in the
6  * LICENSE file in the root directory of this source tree.
7  */
8 
9 #include <fizz/crypto/Utils.h>
10 
11 #include <sodium.h>
12 
13 #include <folly/ssl/Init.h>
14 
15 namespace {
16 
17 class InitFizz {
18  public:
19  InitFizz() {
20  if (sodium_init() == -1) {
21  throw std::runtime_error("Couldn't init libsodium");
22  }
23 
25  }
26 };
27 } // namespace
28 
29 namespace fizz {
30 
31 bool CryptoUtils::equal(folly::ByteRange a, folly::ByteRange b) {
32  if (a.size() != b.size()) {
33  return false;
34  }
35  return sodium_memcmp(a.data(), b.data(), a.size()) == 0;
36 }
37 
38 void CryptoUtils::clean(folly::MutableByteRange range) {
39  sodium_memzero(range.data(), range.size());
40 }
41 
43  static InitFizz initFizz;
44 }
45 } // namespace fizz
char b
constexpr size_type size() const
Definition: Range.h:431
void init()
Definition: Init.cpp:54
void init()
Gen range(Value begin, Value end)
Definition: Base.h:467
constexpr Iter data() const
Definition: Range.h:446
Definition: Actions.h:16
char a