/src/mozilla-central/toolkit/components/resistfingerprinting/RelativeTimeline.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
2 | | /* This Source Code Form is subject to the terms of the Mozilla Public |
3 | | * License, v. 2.0. If a copy of the MPL was not distributed with this |
4 | | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
5 | | |
6 | | #include "nsCOMPtr.h" |
7 | | #include "nsIRandomGenerator.h" |
8 | | #include "nsServiceManagerUtils.h" |
9 | | |
10 | | #include "RelativeTimeline.h" |
11 | | |
12 | | namespace mozilla { |
13 | | |
14 | | int64_t RelativeTimeline::GetRandomTimelineSeed() |
15 | 0 | { |
16 | 0 | if (mRandomTimelineSeed == 0) |
17 | 0 | { |
18 | 0 | nsresult rv; |
19 | 0 | nsCOMPtr<nsIRandomGenerator> randomGenerator = |
20 | 0 | do_GetService("@mozilla.org/security/random-generator;1", &rv); |
21 | 0 | if (NS_WARN_IF(NS_FAILED(rv))) { |
22 | 0 | mRandomTimelineSeed = rand(); |
23 | 0 | return mRandomTimelineSeed; |
24 | 0 | } |
25 | 0 | |
26 | 0 | uint8_t* buffer = nullptr; |
27 | 0 | rv = randomGenerator->GenerateRandomBytes(sizeof(mRandomTimelineSeed), &buffer); |
28 | 0 | if (NS_WARN_IF(NS_FAILED(rv))) { |
29 | 0 | mRandomTimelineSeed = rand(); |
30 | 0 | return mRandomTimelineSeed; |
31 | 0 | } |
32 | 0 | |
33 | 0 | memcpy(&mRandomTimelineSeed, buffer, sizeof(mRandomTimelineSeed)); |
34 | 0 | MOZ_ASSERT(buffer); |
35 | 0 | free(buffer); |
36 | 0 | } |
37 | 0 | return mRandomTimelineSeed; |
38 | 0 | } |
39 | | |
40 | | } // mozilla namespace |