/src/mozilla-central/dom/webauthn/AuthenticatorAssertionResponse.cpp
Line | Count | Source (jump to first uncovered line) |
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 | 0 | NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(AuthenticatorAssertionResponse, |
15 | 0 | AuthenticatorResponse) |
16 | 0 | tmp->mAuthenticatorDataCachedObj = nullptr; |
17 | 0 | tmp->mSignatureCachedObj = nullptr; |
18 | 0 | tmp->mUserHandleCachedObj = nullptr; |
19 | 0 | NS_IMPL_CYCLE_COLLECTION_UNLINK_END |
20 | | |
21 | 0 | NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN_INHERITED(AuthenticatorAssertionResponse, |
22 | 0 | AuthenticatorResponse) |
23 | 0 | NS_IMPL_CYCLE_COLLECTION_TRACE_PRESERVED_WRAPPER |
24 | 0 | NS_IMPL_CYCLE_COLLECTION_TRACE_JS_MEMBER_CALLBACK(mAuthenticatorDataCachedObj) |
25 | 0 | NS_IMPL_CYCLE_COLLECTION_TRACE_JS_MEMBER_CALLBACK(mSignatureCachedObj) |
26 | 0 | NS_IMPL_CYCLE_COLLECTION_TRACE_JS_MEMBER_CALLBACK(mUserHandleCachedObj) |
27 | 0 | NS_IMPL_CYCLE_COLLECTION_TRACE_END |
28 | | |
29 | 0 | NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(AuthenticatorAssertionResponse, |
30 | 0 | AuthenticatorResponse) |
31 | 0 | NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END |
32 | | |
33 | | NS_IMPL_ADDREF_INHERITED(AuthenticatorAssertionResponse, AuthenticatorResponse) |
34 | | NS_IMPL_RELEASE_INHERITED(AuthenticatorAssertionResponse, AuthenticatorResponse) |
35 | | |
36 | 0 | NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(AuthenticatorAssertionResponse) |
37 | 0 | NS_INTERFACE_MAP_END_INHERITING(AuthenticatorResponse) |
38 | | |
39 | | AuthenticatorAssertionResponse::AuthenticatorAssertionResponse(nsPIDOMWindowInner* aParent) |
40 | | : AuthenticatorResponse(aParent) |
41 | | , mAuthenticatorDataCachedObj(nullptr) |
42 | | , mSignatureCachedObj(nullptr) |
43 | | , mUserHandleCachedObj(nullptr) |
44 | 0 | { |
45 | 0 | mozilla::HoldJSObjects(this); |
46 | 0 | } |
47 | | |
48 | | AuthenticatorAssertionResponse::~AuthenticatorAssertionResponse() |
49 | 0 | { |
50 | 0 | mozilla::DropJSObjects(this); |
51 | 0 | } |
52 | | |
53 | | JSObject* |
54 | | AuthenticatorAssertionResponse::WrapObject(JSContext* aCx, |
55 | | JS::Handle<JSObject*> aGivenProto) |
56 | 0 | { |
57 | 0 | return AuthenticatorAssertionResponse_Binding::Wrap(aCx, this, aGivenProto); |
58 | 0 | } |
59 | | |
60 | | void |
61 | | AuthenticatorAssertionResponse::GetAuthenticatorData(JSContext* aCx, |
62 | | JS::MutableHandle<JSObject*> aRetVal) |
63 | 0 | { |
64 | 0 | if (!mAuthenticatorDataCachedObj) { |
65 | 0 | mAuthenticatorDataCachedObj = mAuthenticatorData.ToArrayBuffer(aCx); |
66 | 0 | } |
67 | 0 | aRetVal.set(mAuthenticatorDataCachedObj); |
68 | 0 | } |
69 | | |
70 | | nsresult |
71 | | AuthenticatorAssertionResponse::SetAuthenticatorData(CryptoBuffer& aBuffer) |
72 | 0 | { |
73 | 0 | if (NS_WARN_IF(!mAuthenticatorData.Assign(aBuffer))) { |
74 | 0 | return NS_ERROR_OUT_OF_MEMORY; |
75 | 0 | } |
76 | 0 | return NS_OK; |
77 | 0 | } |
78 | | |
79 | | void |
80 | | AuthenticatorAssertionResponse::GetSignature(JSContext* aCx, |
81 | | JS::MutableHandle<JSObject*> aRetVal) |
82 | 0 | { |
83 | 0 | if (!mSignatureCachedObj) { |
84 | 0 | mSignatureCachedObj = mSignature.ToArrayBuffer(aCx); |
85 | 0 | } |
86 | 0 | aRetVal.set(mSignatureCachedObj); |
87 | 0 | } |
88 | | |
89 | | nsresult |
90 | | AuthenticatorAssertionResponse::SetSignature(CryptoBuffer& aBuffer) |
91 | 0 | { |
92 | 0 | if (NS_WARN_IF(!mSignature.Assign(aBuffer))) { |
93 | 0 | return NS_ERROR_OUT_OF_MEMORY; |
94 | 0 | } |
95 | 0 | return NS_OK; |
96 | 0 | } |
97 | | |
98 | | void |
99 | | AuthenticatorAssertionResponse::GetUserHandle(JSContext* aCx, |
100 | | JS::MutableHandle<JSObject*> aRetVal) |
101 | 0 | { |
102 | 0 | // Per https://w3c.github.io/webauthn/#ref-for-dom-authenticatorassertionresponse-userhandle%E2%91%A0 |
103 | 0 | // this should return null if the handle is unset. |
104 | 0 | if (mUserHandle.IsEmpty()) { |
105 | 0 | aRetVal.set(nullptr); |
106 | 0 | } else { |
107 | 0 | if (!mUserHandleCachedObj) { |
108 | 0 | mUserHandleCachedObj = mUserHandle.ToArrayBuffer(aCx); |
109 | 0 | } |
110 | 0 | aRetVal.set(mUserHandleCachedObj); |
111 | 0 | } |
112 | 0 | } |
113 | | |
114 | | nsresult |
115 | | AuthenticatorAssertionResponse::SetUserHandle(CryptoBuffer& aBuffer) |
116 | 0 | { |
117 | 0 | if (NS_WARN_IF(!mUserHandle.Assign(aBuffer))) { |
118 | 0 | return NS_ERROR_OUT_OF_MEMORY; |
119 | 0 | } |
120 | 0 | return NS_OK; |
121 | 0 | } |
122 | | |
123 | | } // namespace dom |
124 | | } // namespace mozilla |