Bug 1854550 - pt 10. Allow LOG() with zero extra arguments r=glandium
[gecko.git] / dom / webauthn / WebAuthnArgs.cpp
blobf679041bbcaf63478ef5ed983a0ce102317ea2f1
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 file,
5 * You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #include "WebAuthnArgs.h"
8 #include "WebAuthnEnumStrings.h"
9 #include "WebAuthnUtil.h"
10 #include "mozilla/dom/PWebAuthnTransactionParent.h"
12 namespace mozilla::dom {
14 NS_IMPL_ISUPPORTS(WebAuthnRegisterArgs, nsIWebAuthnRegisterArgs)
16 NS_IMETHODIMP
17 WebAuthnRegisterArgs::GetOrigin(nsAString& aOrigin) {
18 aOrigin = mInfo.Origin();
19 return NS_OK;
22 NS_IMETHODIMP
23 WebAuthnRegisterArgs::GetChallenge(nsTArray<uint8_t>& aChallenge) {
24 aChallenge.Assign(mInfo.Challenge());
25 return NS_OK;
28 NS_IMETHODIMP
29 WebAuthnRegisterArgs::GetClientDataHash(nsTArray<uint8_t>& aClientDataHash) {
30 nsresult rv = HashCString(mInfo.ClientDataJSON(), aClientDataHash);
31 if (NS_WARN_IF(NS_FAILED(rv))) {
32 return NS_ERROR_FAILURE;
35 return NS_OK;
38 NS_IMETHODIMP
39 WebAuthnRegisterArgs::GetRpId(nsAString& aRpId) {
40 aRpId = mInfo.RpId();
41 return NS_OK;
44 NS_IMETHODIMP
45 WebAuthnRegisterArgs::GetRpName(nsAString& aRpName) {
46 aRpName = mInfo.Rp().Name();
47 return NS_OK;
50 NS_IMETHODIMP
51 WebAuthnRegisterArgs::GetUserId(nsTArray<uint8_t>& aUserId) {
52 aUserId.Assign(mInfo.User().Id());
53 return NS_OK;
56 NS_IMETHODIMP
57 WebAuthnRegisterArgs::GetUserName(nsAString& aUserName) {
58 aUserName = mInfo.User().Name();
59 return NS_OK;
62 NS_IMETHODIMP
63 WebAuthnRegisterArgs::GetUserDisplayName(nsAString& aUserDisplayName) {
64 aUserDisplayName = mInfo.User().DisplayName();
65 return NS_OK;
68 NS_IMETHODIMP
69 WebAuthnRegisterArgs::GetCoseAlgs(nsTArray<int32_t>& aCoseAlgs) {
70 aCoseAlgs.Clear();
71 for (const CoseAlg& coseAlg : mInfo.coseAlgs()) {
72 aCoseAlgs.AppendElement(coseAlg.alg());
74 return NS_OK;
77 NS_IMETHODIMP
78 WebAuthnRegisterArgs::GetExcludeList(
79 nsTArray<nsTArray<uint8_t> >& aExcludeList) {
80 aExcludeList.Clear();
81 for (const WebAuthnScopedCredential& cred : mInfo.ExcludeList()) {
82 aExcludeList.AppendElement(cred.id().Clone());
84 return NS_OK;
87 NS_IMETHODIMP
88 WebAuthnRegisterArgs::GetExcludeListTransports(
89 nsTArray<uint8_t>& aExcludeListTransports) {
90 aExcludeListTransports.Clear();
91 for (const WebAuthnScopedCredential& cred : mInfo.ExcludeList()) {
92 aExcludeListTransports.AppendElement(cred.transports());
94 return NS_OK;
97 NS_IMETHODIMP
98 WebAuthnRegisterArgs::GetCredProps(bool* aCredProps) {
99 *aCredProps = mCredProps;
101 return NS_OK;
104 NS_IMETHODIMP
105 WebAuthnRegisterArgs::GetHmacCreateSecret(bool* aHmacCreateSecret) {
106 *aHmacCreateSecret = mHmacCreateSecret;
108 return NS_OK;
111 NS_IMETHODIMP
112 WebAuthnRegisterArgs::GetMinPinLength(bool* aMinPinLength) {
113 *aMinPinLength = mMinPinLength;
115 return NS_OK;
118 NS_IMETHODIMP
119 WebAuthnRegisterArgs::GetResidentKey(nsAString& aResidentKey) {
120 aResidentKey = mInfo.AuthenticatorSelection().residentKey();
121 return NS_OK;
124 NS_IMETHODIMP
125 WebAuthnRegisterArgs::GetUserVerification(
126 nsAString& aUserVerificationRequirement) {
127 aUserVerificationRequirement =
128 mInfo.AuthenticatorSelection().userVerificationRequirement();
129 return NS_OK;
132 NS_IMETHODIMP
133 WebAuthnRegisterArgs::GetAuthenticatorAttachment(
134 nsAString& aAuthenticatorAttachment) {
135 if (mInfo.AuthenticatorSelection().authenticatorAttachment().isNothing()) {
136 return NS_ERROR_NOT_AVAILABLE;
138 aAuthenticatorAttachment =
139 *mInfo.AuthenticatorSelection().authenticatorAttachment();
140 return NS_OK;
143 NS_IMETHODIMP
144 WebAuthnRegisterArgs::GetTimeoutMS(uint32_t* aTimeoutMS) {
145 *aTimeoutMS = mInfo.TimeoutMS();
146 return NS_OK;
149 NS_IMETHODIMP
150 WebAuthnRegisterArgs::GetAttestationConveyancePreference(
151 nsAString& aAttestationConveyancePreference) {
152 aAttestationConveyancePreference = mInfo.attestationConveyancePreference();
153 return NS_OK;
156 NS_IMPL_ISUPPORTS(WebAuthnSignArgs, nsIWebAuthnSignArgs)
158 NS_IMETHODIMP
159 WebAuthnSignArgs::GetOrigin(nsAString& aOrigin) {
160 aOrigin = mInfo.Origin();
161 return NS_OK;
164 NS_IMETHODIMP
165 WebAuthnSignArgs::GetRpId(nsAString& aRpId) {
166 aRpId = mInfo.RpId();
167 return NS_OK;
170 NS_IMETHODIMP
171 WebAuthnSignArgs::GetChallenge(nsTArray<uint8_t>& aChallenge) {
172 aChallenge.Assign(mInfo.Challenge());
173 return NS_OK;
176 NS_IMETHODIMP
177 WebAuthnSignArgs::GetClientDataHash(nsTArray<uint8_t>& aClientDataHash) {
178 nsresult rv = HashCString(mInfo.ClientDataJSON(), aClientDataHash);
179 if (NS_WARN_IF(NS_FAILED(rv))) {
180 return NS_ERROR_FAILURE;
183 return NS_OK;
186 NS_IMETHODIMP
187 WebAuthnSignArgs::GetAllowList(nsTArray<nsTArray<uint8_t> >& aAllowList) {
188 aAllowList.Clear();
189 for (const WebAuthnScopedCredential& cred : mInfo.AllowList()) {
190 aAllowList.AppendElement(cred.id().Clone());
192 return NS_OK;
195 NS_IMETHODIMP
196 WebAuthnSignArgs::GetAllowListTransports(
197 nsTArray<uint8_t>& aAllowListTransports) {
198 aAllowListTransports.Clear();
199 for (const WebAuthnScopedCredential& cred : mInfo.AllowList()) {
200 aAllowListTransports.AppendElement(cred.transports());
202 return NS_OK;
205 NS_IMETHODIMP
206 WebAuthnSignArgs::GetHmacCreateSecret(bool* aHmacCreateSecret) {
207 for (const WebAuthnExtension& ext : mInfo.Extensions()) {
208 if (ext.type() == WebAuthnExtension::TWebAuthnExtensionHmacSecret) {
209 *aHmacCreateSecret =
210 ext.get_WebAuthnExtensionHmacSecret().hmacCreateSecret();
211 return NS_OK;
215 return NS_ERROR_NOT_AVAILABLE;
218 NS_IMETHODIMP
219 WebAuthnSignArgs::GetAppId(nsAString& aAppId) {
220 for (const WebAuthnExtension& ext : mInfo.Extensions()) {
221 if (ext.type() == WebAuthnExtension::TWebAuthnExtensionAppId) {
222 aAppId = ext.get_WebAuthnExtensionAppId().appIdentifier();
223 return NS_OK;
227 return NS_ERROR_NOT_AVAILABLE;
230 NS_IMETHODIMP
231 WebAuthnSignArgs::GetUserVerification(nsAString& aUserVerificationRequirement) {
232 aUserVerificationRequirement = mInfo.userVerificationRequirement();
233 return NS_OK;
236 NS_IMETHODIMP
237 WebAuthnSignArgs::GetTimeoutMS(uint32_t* aTimeoutMS) {
238 *aTimeoutMS = mInfo.TimeoutMS();
239 return NS_OK;
242 } // namespace mozilla::dom