1 // 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.
5 #include "ipc/brokerable_attachment.h"
7 #include "crypto/random.h"
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.
16 BrokerableAttachment::AttachmentId
GetRandomId() {
17 BrokerableAttachment::AttachmentId id
;
18 crypto::RandBytes(id
.nonce
, BrokerableAttachment::kNonceSize
);
24 BrokerableAttachment::BrokerableAttachment()
25 : id_(GetRandomId()), needs_brokering_(false) {}
27 BrokerableAttachment::BrokerableAttachment(const AttachmentId
& id
,
29 : id_(id
), needs_brokering_(needs_brokering
) {}
31 BrokerableAttachment::~BrokerableAttachment() {
34 BrokerableAttachment::AttachmentId
BrokerableAttachment::GetIdentifier() const {
38 bool BrokerableAttachment::NeedsBrokering() const {
39 return needs_brokering_
;
42 void BrokerableAttachment::SetNeedsBrokering(bool needs_brokering
) {
43 needs_brokering_
= needs_brokering
;
46 BrokerableAttachment::Type
BrokerableAttachment::GetType() const {
47 return TYPE_BROKERABLE_ATTACHMENT
;