Source code

Revision control

Other Tools

1
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
3
/* This Source Code Form is subject to the terms of the Mozilla Public
4
* License, v. 2.0. If a copy of the MPL was not distributed with this
5
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6
7
#include "mozilla/dom/WebAuthenticationBinding.h"
8
#include "mozilla/dom/AuthenticatorAssertionResponse.h"
9
10
namespace mozilla {
11
namespace dom {
12
13
NS_IMPL_CYCLE_COLLECTION_CLASS(AuthenticatorAssertionResponse)
14
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(AuthenticatorAssertionResponse,
15
AuthenticatorResponse)
16
tmp->mAuthenticatorDataCachedObj = nullptr;
17
tmp->mSignatureCachedObj = nullptr;
18
tmp->mUserHandleCachedObj = nullptr;
19
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
20
21
NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN_INHERITED(AuthenticatorAssertionResponse,
22
AuthenticatorResponse)
23
NS_IMPL_CYCLE_COLLECTION_TRACE_PRESERVED_WRAPPER
24
NS_IMPL_CYCLE_COLLECTION_TRACE_JS_MEMBER_CALLBACK(mAuthenticatorDataCachedObj)
25
NS_IMPL_CYCLE_COLLECTION_TRACE_JS_MEMBER_CALLBACK(mSignatureCachedObj)
26
NS_IMPL_CYCLE_COLLECTION_TRACE_JS_MEMBER_CALLBACK(mUserHandleCachedObj)
27
NS_IMPL_CYCLE_COLLECTION_TRACE_END
28
29
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(
30
AuthenticatorAssertionResponse, AuthenticatorResponse)
31
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
32
33
NS_IMPL_ADDREF_INHERITED(AuthenticatorAssertionResponse, AuthenticatorResponse)
34
NS_IMPL_RELEASE_INHERITED(AuthenticatorAssertionResponse, AuthenticatorResponse)
35
36
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(AuthenticatorAssertionResponse)
37
NS_INTERFACE_MAP_END_INHERITING(AuthenticatorResponse)
38
39
AuthenticatorAssertionResponse::AuthenticatorAssertionResponse(
40
nsPIDOMWindowInner* aParent)
41
: AuthenticatorResponse(aParent),
42
mAuthenticatorDataCachedObj(nullptr),
43
mSignatureCachedObj(nullptr),
44
mUserHandleCachedObj(nullptr) {
45
mozilla::HoldJSObjects(this);
46
}
47
48
AuthenticatorAssertionResponse::~AuthenticatorAssertionResponse() {
49
mozilla::DropJSObjects(this);
50
}
51
52
JSObject* AuthenticatorAssertionResponse::WrapObject(
53
JSContext* aCx, JS::Handle<JSObject*> aGivenProto) {
54
return AuthenticatorAssertionResponse_Binding::Wrap(aCx, this, aGivenProto);
55
}
56
57
void AuthenticatorAssertionResponse::GetAuthenticatorData(
58
JSContext* aCx, JS::MutableHandle<JSObject*> aRetVal) {
59
if (!mAuthenticatorDataCachedObj) {
60
mAuthenticatorDataCachedObj = mAuthenticatorData.ToArrayBuffer(aCx);
61
}
62
aRetVal.set(mAuthenticatorDataCachedObj);
63
}
64
65
nsresult AuthenticatorAssertionResponse::SetAuthenticatorData(
66
CryptoBuffer& aBuffer) {
67
if (NS_WARN_IF(!mAuthenticatorData.Assign(aBuffer))) {
68
return NS_ERROR_OUT_OF_MEMORY;
69
}
70
return NS_OK;
71
}
72
73
void AuthenticatorAssertionResponse::GetSignature(
74
JSContext* aCx, JS::MutableHandle<JSObject*> aRetVal) {
75
if (!mSignatureCachedObj) {
76
mSignatureCachedObj = mSignature.ToArrayBuffer(aCx);
77
}
78
aRetVal.set(mSignatureCachedObj);
79
}
80
81
nsresult AuthenticatorAssertionResponse::SetSignature(CryptoBuffer& aBuffer) {
82
if (NS_WARN_IF(!mSignature.Assign(aBuffer))) {
83
return NS_ERROR_OUT_OF_MEMORY;
84
}
85
return NS_OK;
86
}
87
88
void AuthenticatorAssertionResponse::GetUserHandle(
89
JSContext* aCx, JS::MutableHandle<JSObject*> aRetVal) {
90
// Per
92
// this should return null if the handle is unset.
93
if (mUserHandle.IsEmpty()) {
94
aRetVal.set(nullptr);
95
} else {
96
if (!mUserHandleCachedObj) {
97
mUserHandleCachedObj = mUserHandle.ToArrayBuffer(aCx);
98
}
99
aRetVal.set(mUserHandleCachedObj);
100
}
101
}
102
103
nsresult AuthenticatorAssertionResponse::SetUserHandle(CryptoBuffer& aBuffer) {
104
if (NS_WARN_IF(!mUserHandle.Assign(aBuffer))) {
105
return NS_ERROR_OUT_OF_MEMORY;
106
}
107
return NS_OK;
108
}
109
110
} // namespace dom
111
} // namespace mozilla