blob: 9af40d9ed50197bf473699bb1e5a82d29a13a984 [file] [log] [blame]
erikchen151b2f92015-06-16 20:20:511// Copyright 2015 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "ipc/brokerable_attachment.h"
6
erikcheneece6c32015-07-07 22:13:117#include "crypto/random.h"
8
erikchen151b2f92015-06-16 20:20:519namespace IPC {
10
erikcheneece6c32015-07-07 22:13:1111namespace {
12
13// In order to prevent mutually untrusted processes from stealing resources from
14// one another, the nonce must be secret. This generates a 128-bit,
15// cryptographicaly-strong random number.
16BrokerableAttachment::AttachmentId GetRandomId() {
17 BrokerableAttachment::AttachmentId id;
18 crypto::RandBytes(id.nonce, BrokerableAttachment::kNonceSize);
19 return id;
20}
21
22} // namespace
23
erikchende9412b82015-07-27 18:26:1424BrokerableAttachment::BrokerableAttachment()
25 : id_(GetRandomId()), needs_brokering_(false) {
erikchen151b2f92015-06-16 20:20:5126}
27
erikchende9412b82015-07-27 18:26:1428BrokerableAttachment::BrokerableAttachment(const AttachmentId& id,
29 bool needs_brokering)
30 : id_(id), needs_brokering_(needs_brokering) {
erikchen7252aa362015-07-15 01:35:3931}
32
erikchen151b2f92015-06-16 20:20:5133BrokerableAttachment::~BrokerableAttachment() {
34}
35
36BrokerableAttachment::AttachmentId BrokerableAttachment::GetIdentifier() const {
37 return id_;
38}
39
erikchende9412b82015-07-27 18:26:1440bool BrokerableAttachment::NeedsBrokering() const {
41 return needs_brokering_;
42}
43
44void BrokerableAttachment::SetNeedsBrokering(bool needs_brokering) {
45 needs_brokering_ = needs_brokering;
46}
47
erikcheneece6c32015-07-07 22:13:1148BrokerableAttachment::Type BrokerableAttachment::GetType() const {
49 return TYPE_BROKERABLE_ATTACHMENT;
50}
51
erikchen151b2f92015-06-16 20:20:5152} // namespace IPC