blob: f1cc9b2afaa624b7b61d33b9f83539c159b33779 [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
erikchen06faf0c2015-08-27 19:49:5811namespace {
erikcheneece6c32015-07-07 22:13:1112
erikchen06faf0c2015-08-27 19:49:5813// 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;
erikcheneece6c32015-07-07 22:13:1120}
21
erikchen06faf0c2015-08-27 19:49:5822} // namespace
23
24BrokerableAttachment::BrokerableAttachment()
25 : id_(GetRandomId()), needs_brokering_(false) {}
26
27BrokerableAttachment::BrokerableAttachment(const AttachmentId& id,
28 bool needs_brokering)
29 : id_(id), needs_brokering_(needs_brokering) {}
30
31BrokerableAttachment::~BrokerableAttachment() {
erikchen151b2f92015-06-16 20:20:5132}
33
34BrokerableAttachment::AttachmentId BrokerableAttachment::GetIdentifier() const {
35 return id_;
36}
37
erikchende9412b82015-07-27 18:26:1438bool BrokerableAttachment::NeedsBrokering() const {
erikchen06faf0c2015-08-27 19:49:5839 return needs_brokering_;
40}
41
42void BrokerableAttachment::SetNeedsBrokering(bool needs_brokering) {
43 needs_brokering_ = needs_brokering;
erikchende9412b82015-07-27 18:26:1444}
45
erikcheneece6c32015-07-07 22:13:1146BrokerableAttachment::Type BrokerableAttachment::GetType() const {
47 return TYPE_BROKERABLE_ATTACHMENT;
48}
49
erikchen151b2f92015-06-16 20:20:5150} // namespace IPC