Add const to data buffers and strings in data types 32/307832/1
authorKrzysztof Malysa <k.malysa@samsung.com>
Wed, 13 Mar 2024 11:36:07 +0000 (12:36 +0100)
committerKrzysztof Malysa <k.malysa@samsung.com>
Wed, 13 Mar 2024 11:36:59 +0000 (12:36 +0100)
Specifically:
- change char* to const char* in input data
- change wauthn_buffer_s to wauthn_const_buffer_s in input data

This prevents the need to use const_cast while creating the input data.

Change-Id: I3d6c06848010b8d962eb7a337a3b3a1d27601e16

include/webauthn-types.h
srcs/common/serialization.cpp
srcs/common/serialization.h
srcs/common/utils.cpp
tests/serialization-test.cpp
tests/webauthn-client-test.cpp

index bf8e6c54f6cf18a26e50456041472715bb26736e..c983dffb54ff6ede7b7c1f0510db7da3fa57c232 100644 (file)
@@ -175,13 +175,13 @@ typedef enum __wauthn_pubkey_cred_type {
 } wauthn_pubkey_cred_type_e;
 
 /**
- * @brief The structure for binary buffer used in this CAPI.
+ * @brief The structure for const binary buffer used in this CAPI.
  * @since_tizen 9.0
  */
-typedef struct __wauthn_buffer {
-    unsigned char *data; /**< Byte array containing binary data */
+typedef struct __wauthn_const_buffer {
+    const unsigned char *data; /**< Byte array containing binary data */
     size_t size; /**< The size of the binary data */
-} wauthn_buffer_s;
+} wauthn_const_buffer_s;
 
 /**
  * @brief The structure for response of wauthn_make_credential.
@@ -192,12 +192,12 @@ typedef struct __wauthn_buffer {
  * @see #wauthn_cose_algorithm_e
  */
 typedef struct __wauthn_authenticator_attestation_response {
-    wauthn_buffer_s *client_data_json;
-    wauthn_buffer_s *attestation_object; /**< The CBOR encoded Attestation Object to be returned to the RP */
+    wauthn_const_buffer_s *client_data_json;
+    wauthn_const_buffer_s *attestation_object; /**< The CBOR encoded Attestation Object to be returned to the RP */
     unsigned int transports; /**< To represent multiple transports,
                                 #wauthn_authenticator_transport_e can be ORed multiple times */
-    wauthn_buffer_s *authenticator_data;
-    wauthn_buffer_s *subject_pubkey_info;
+    wauthn_const_buffer_s *authenticator_data;
+    wauthn_const_buffer_s *subject_pubkey_info;
     wauthn_cose_algorithm_e pubkey_alg;
 } wauthn_authenticator_attestation_response_s;
 
@@ -208,11 +208,11 @@ typedef struct __wauthn_authenticator_attestation_response {
  * @see #wauthn_pubkey_credential_assertion_s
  */
 typedef struct __wauthn_authenticator_assertion_response {
-    wauthn_buffer_s *client_data_json;
-    wauthn_buffer_s *authenticator_data;
-    wauthn_buffer_s *signature;
-    wauthn_buffer_s *user_handle;
-    wauthn_buffer_s *attestation_object;
+    wauthn_const_buffer_s *client_data_json;
+    wauthn_const_buffer_s *authenticator_data;
+    wauthn_const_buffer_s *signature;
+    wauthn_const_buffer_s *user_handle;
+    wauthn_const_buffer_s *attestation_object;
 } wauthn_authenticator_assertion_response_s;
 
 /**
@@ -220,8 +220,8 @@ typedef struct __wauthn_authenticator_assertion_response {
  * @since_tizen 9.0
  */
 typedef struct __wauthn_rp_entity {
-    char *name; /**< The name of RP */
-    char *id; /**< The RPID */
+    const char *name; /**< The name of RP */
+    const char *id; /**< The RPID */
 } wauthn_rp_entity_s;
 
 #define WEBAUTHN_MAX_USER_ID_LENGTH                                64
@@ -231,10 +231,10 @@ typedef struct __wauthn_rp_entity {
  * @since_tizen 9.0
  */
 typedef struct __wauthn_user_entity {
-    char *name;
-    wauthn_buffer_s *id; /**< The ID of the user account. An ID is a byte sequence with a maximum size of
+    const char *name;
+    wauthn_const_buffer_s *id; /**< The ID of the user account. An ID is a byte sequence with a maximum size of
                          64 bytes, and is not meant to be displayed to the user */
-    char *display_name; /**< A human-palatable name for the user account, intended only for display */
+    const char *display_name; /**< A human-palatable name for the user account, intended only for display */
 } wauthn_user_entity_s;
 
 
@@ -267,7 +267,7 @@ typedef struct __wauthn_pubkey_cred_params {
  */
 typedef struct __wauthn_pubkey_cred_descriptor {
     wauthn_pubkey_cred_type_e type;
-    wauthn_buffer_s *id;
+    wauthn_const_buffer_s *id;
     unsigned int transports; /**< To represent multiple transports,
                                 #wauthn_authenticator_transport_e can be ORed multiple times */
 } wauthn_pubkey_cred_descriptor_s;
@@ -288,10 +288,10 @@ typedef struct __wauthn_pubkey_cred_descriptors {
  * @see #wauthn_authentication_ext_s
  */
 typedef struct __wauthn_authentication_ext {
-    wauthn_buffer_s *extension_id;  /**<
+    wauthn_const_buffer_s *extension_id;  /**<
         Extension Identifier defined in the following registry.
         https://www.iana.org/assignments/webauthn/webauthn.xhtml#webauthn-extension-ids. */
-    wauthn_buffer_s *extension_value; /**<
+    wauthn_const_buffer_s *extension_value; /**<
         Extension value */
 } wauthn_authentication_ext_s;
 
@@ -334,14 +334,14 @@ typedef struct __wauthn_pubkey_cred_hints {
  * @since_tizen 9.0
  */
 typedef struct __wauthn_hybrid_linked_data {
-    wauthn_buffer_s *contact_id;           // cbor:"1"
-    wauthn_buffer_s *link_id;              // cbor:"2"
-    wauthn_buffer_s *link_secret;          // cbor:"3"
-    wauthn_buffer_s *authenticator_pubkey; // cbor:"4"
-    wauthn_buffer_s *authenticator_name;   // cbor:"5"
-    wauthn_buffer_s *signature;            // cbor:"6"
-    wauthn_buffer_s *auth_pubkey;
-    wauthn_buffer_s *tunnel_server_domain;
+    wauthn_const_buffer_s *contact_id;           // cbor:"1"
+    wauthn_const_buffer_s *link_id;              // cbor:"2"
+    wauthn_const_buffer_s *link_secret;          // cbor:"3"
+    wauthn_const_buffer_s *authenticator_pubkey; // cbor:"4"
+    wauthn_const_buffer_s *authenticator_name;   // cbor:"5"
+    wauthn_const_buffer_s *signature;            // cbor:"6"
+    wauthn_const_buffer_s *auth_pubkey;
+    wauthn_const_buffer_s *tunnel_server_domain;
 } wauthn_hybrid_linked_data_s;
 
 /**
@@ -350,7 +350,7 @@ typedef struct __wauthn_hybrid_linked_data {
  */
 typedef struct __wauthn_attestation_formats {
     size_t size;
-    wauthn_buffer_s *attestation_formats;
+    wauthn_const_buffer_s *attestation_formats;
 } wauthn_attestation_formats_s;
 
 /**
@@ -375,11 +375,11 @@ typedef struct __wauthn_pubkey_cred_creation_options {
     wauthn_user_entity_s *user; /**< This member contains names and
                                 an identifier for the user account
                                 performing the registration */
-    wauthn_buffer_s *challenge; /**< This member specifies a challenge
-                                that the authenticator signs,
-                                along with other data, when producing
-                                an attestation object for the newly
-                                created credential */
+    wauthn_const_buffer_s *challenge; /**< This member specifies a challenge
+                                      that the authenticator signs,
+                                      along with other data, when producing
+                                      an attestation object for the newly
+                                      created credential */
     wauthn_pubkey_cred_params_s *pubkey_cred_params; /**< This member lists the key types and
                                                      signature algorithms the Relying Party
                                                      supports, ordered from most preferred
@@ -426,12 +426,13 @@ typedef struct __wauthn_pubkey_cred_creation_options {
  * @see #wauthn_hybrid_linked_data_s
  */
 typedef struct __wauthn_pubkey_cred_request_options {
-    wauthn_buffer_s *challenge; /**< This member specifies a challenge that the authenticator signs,
-                                along with other data, when producing an authentication assertion */
+    wauthn_const_buffer_s *challenge; /**< This member specifies a challenge that the authenticator
+                                      signs, along with other data, when producing
+                                      an authentication assertion */
     unsigned long timeout; /**< This member specifies a time, in milliseconds,
         that the Relying Party is willing to wait for the call to complete.
         The value, '0', means no timeout is set. (optional)*/
-    char *rpId;        /**< This member specifies the RP ID claimed by the Relying Party (optional)*/
+    const char *rpId; /**< This member specifies the RP ID claimed by the Relying Party (optional)*/
     wauthn_pubkey_cred_descriptors_s *allow_credentials; /**< This member is used by the client
                                                          to find authenticators eligible for this
                                                          authentication ceremony (optional)*/
@@ -466,14 +467,14 @@ typedef struct __wauthn_pubkey_cred_request_options {
  * @see #wauthn_hybrid_linked_data_s
  */
 typedef struct __wauthn_pubkey_credential_attestaion {
-    wauthn_buffer_s *id;
+    wauthn_const_buffer_s *id;
     wauthn_pubkey_cred_type_e type;
-    wauthn_buffer_s *rawId;
+    wauthn_const_buffer_s *rawId;
     wauthn_authenticator_attestation_response_s *response;
     wauthn_authenticator_attachment_e authenticator_attachment;
     wauthn_authentication_exts_s *extensions;
     bool is_conditional_mediation_available;
-    wauthn_buffer_s *json_data;
+    wauthn_const_buffer_s *json_data;
     wauthn_hybrid_linked_data_s *linked_device;
 } wauthn_pubkey_credential_attestaion_s;
 
@@ -488,14 +489,14 @@ typedef struct __wauthn_pubkey_credential_attestaion {
  * @see #wauthn_hybrid_linked_data_s
  */
 typedef struct __wauthn_pubkey_credential_assertion {
-    wauthn_buffer_s *id;
+    wauthn_const_buffer_s *id;
     wauthn_pubkey_cred_type_e type;
-    wauthn_buffer_s *rawId;
+    wauthn_const_buffer_s *rawId;
     wauthn_authenticator_assertion_response_s *response;
     wauthn_authenticator_attachment_e authenticator_attachment;
     wauthn_authentication_exts_s *extensions;
     bool is_conditional_mediation_available;
-    wauthn_buffer_s *json_data;
+    wauthn_const_buffer_s *json_data;
     wauthn_hybrid_linked_data_s *linked_device;
 } wauthn_pubkey_credential_assertion_s;
 
@@ -505,7 +506,7 @@ typedef struct __wauthn_pubkey_credential_assertion {
  * @see #wauthn_hash_algorithm_e
  */
 typedef struct __wauthn_client_data {
-    wauthn_buffer_s *client_data_json;// UTF-8 encoded JSON serialization of the client data
+    wauthn_const_buffer_s *client_data_json;// UTF-8 encoded JSON serialization of the client data
     wauthn_hash_algorithm_e hash_alg; // Hash algorithm used to hash the client_data_json field
 } wauthn_client_data_s;
 
index 6ced2fcab46d2e259ab344fb668737de6074721f..50e732bcf9af984e26111d7594f075e44ee2a56a 100644 (file)
@@ -48,7 +48,7 @@ void WAuthnCtypeSerializer::deserializeStructBody(IStream& stream, void **data,
     if (data == nullptr)
         ThrowMsg(SerializationException::InvalidStreamData, "nullptr data.");
     size_t length = 0;
-    deserialize(stream, reinterpret_cast<unsigned char**>(data), &length);
+    deserialize(stream, const_cast<const unsigned char**>(reinterpret_cast<unsigned char**>(data)), &length);
     if (length != 0 && length != struct_size)
         ThrowMsg(SerializationException::InvalidStreamData, "Invalid length: length=" << length
                                                             << ", struct_size=" << struct_size);
@@ -69,7 +69,7 @@ void WAuthnCtypeSerializer::serialize(IStream& stream, const unsigned char* data
     if (length != 0)
         stream.Write(length, data);
 }
-void WAuthnCtypeSerializer::deserialize(IStream& stream, unsigned char** data, size_t* length) {
+void WAuthnCtypeSerializer::deserialize(IStream& stream, const unsigned char** data, size_t* length) {
     if (data == nullptr || length == nullptr)
         ThrowMsg(SerializationException::InvalidStreamData,
             "nullptr data or length. data=" << data << ", length=" << length);
@@ -93,11 +93,11 @@ void WAuthnCtypeSerializer::serialize(IStream& stream, const char* data) {
     size_t length = (data) ? strlen(data) + 1 : 0;
     serialize(stream, reinterpret_cast<const unsigned char*>(data), length);
 }
-void WAuthnCtypeSerializer::deserialize(IStream& stream, char** data) {
+void WAuthnCtypeSerializer::deserialize(IStream& stream, const char** data) {
     if (data == nullptr)
         ThrowMsg(SerializationException::InvalidStreamData, "nullptr data");
     size_t length;
-    deserialize(stream, reinterpret_cast<unsigned char**>(data), &length);
+    deserialize(stream, reinterpret_cast<const unsigned char**>(data), &length);
     if (*data != nullptr && length != strlen(*data) + 1)
         ThrowMsg(SerializationException::InvalidStreamData,
                 "Invalid length of cstring (not expected one): "
@@ -124,26 +124,26 @@ void WAuthnCtypeSerializer::deserialize(IStream& stream, wauthn_error_e* data) {
     __checkValidity(*data);
 }
 
-// For wauthn_buffer_s
-void __checkValidity(const wauthn_buffer_s* data) {
+// For wauthn_const_buffer_s
+void __checkValidity(const wauthn_const_buffer_s* data) {
     if (data == nullptr)
         return;
     if (data->data == nullptr && data->size != 0)
         ThrowMsg(SerializationException::InvalidStreamData,
             "Empty data with size=" << data->size);
 }
-void WAuthnCtypeSerializer::serialize(IStream& stream, const wauthn_buffer_s* data) {
+void WAuthnCtypeSerializer::serialize(IStream& stream, const wauthn_const_buffer_s* data) {
     __checkValidity(data);
     // Seriallize struct itself
-    serializeStructBody(stream, reinterpret_cast<const void *>(data), sizeof(wauthn_buffer_s));
+    serializeStructBody(stream, reinterpret_cast<const void *>(data), sizeof(wauthn_const_buffer_s));
     if (data == nullptr)
         return;
     // Seriallize the contents of struct's pointers
     serialize(stream, data->data, data->size);
 }
-void WAuthnCtypeSerializer::deserialize(IStream& stream, wauthn_buffer_s** data) {
+void WAuthnCtypeSerializer::deserialize(IStream& stream, wauthn_const_buffer_s** data) {
     // Deseriallize struct itself
-    deserializeStructBody(stream, reinterpret_cast<void **>(data), sizeof(wauthn_buffer_s));
+    deserializeStructBody(stream, reinterpret_cast<void**>(data), sizeof(wauthn_const_buffer_s));
     __checkValidity(*data);
     if (*data == nullptr)
         return;
@@ -618,10 +618,10 @@ void __checkValidity(const wauthn_attestation_formats_s* data) {
         ThrowMsg(SerializationException::InvalidStreamData,
             "Inconsistent pointer & length: pointer=" << data->attestation_formats << ", size=" << data->size);
 }
-void __serializePointerContents(IStream& stream, const wauthn_buffer_s* data) {
+void __serializePointerContents(IStream& stream, const wauthn_const_buffer_s* data) {
     WAuthnCtypeSerializer::serialize(stream, data);
 }
-void __deserializePointerContents(IStream& stream, wauthn_buffer_s* data) {
+void __deserializePointerContents(IStream& stream, wauthn_const_buffer_s* data) {
     WAuthnCtypeSerializer::deserialize(stream, &data);
 }
 void WAuthnCtypeSerializer::serialize(IStream& stream, const wauthn_attestation_formats_s* data) {
@@ -632,7 +632,7 @@ void WAuthnCtypeSerializer::serialize(IStream& stream, const wauthn_attestation_
         return;
     // Serialize array
     for(size_t i=0; i < data->size; i++ )
-        __serializeArrayItem(stream, reinterpret_cast<const void *>(data->attestation_formats + i), sizeof(wauthn_buffer_s));
+        __serializeArrayItem(stream, reinterpret_cast<const void *>(data->attestation_formats + i), sizeof(wauthn_const_buffer_s));
     // Seriallize the contents of pointers in struct array
     for(size_t i=0; i < data->size; i++ )
         __serializePointerContents(stream, data->attestation_formats + i);
@@ -648,9 +648,9 @@ void WAuthnCtypeSerializer::deserialize(IStream& stream, wauthn_attestation_form
     }
     __checkValidity(*data);
     // Deseriallize array
-    wauthn_buffer_s* tmp;
+    wauthn_const_buffer_s* tmp;
     for(size_t i=0; i < (*data)->size; i++ ) {
-        __deserializeArrayItem(stream, reinterpret_cast<void **>(&tmp), sizeof(wauthn_buffer_s));
+        __deserializeArrayItem(stream, reinterpret_cast<void **>(&tmp), sizeof(wauthn_const_buffer_s));
         if (i == 0) // set pointer to the first parameter
             (*data)->attestation_formats = tmp;
     }
index 5aa28be3f0fb031a04ed81fc0ad91f25fd2e9c46..ed9dfd94b1aeeb2e8ab9f7a9c4038c5f3a341e43 100644 (file)
@@ -72,16 +72,16 @@ private:
 
 public:
     static void serialize(IStream& stream, const unsigned char* data, size_t length);
-    static void deserialize(IStream& stream, unsigned char** data, size_t* length);
+    static void deserialize(IStream& stream, const unsigned char** data, size_t* length);
 
     static void serialize(IStream& stream, const char* data);
-    static void deserialize(IStream& stream, char** data);
+    static void deserialize(IStream& stream, const char** data);
 
     static void serialize(IStream& stream, const wauthn_error_e data);
     static void deserialize(IStream& stream, wauthn_error_e* data);
 
-    static void serialize(IStream& stream, const wauthn_buffer_s* data);
-    static void deserialize(IStream& stream, wauthn_buffer_s** data);
+    static void serialize(IStream& stream, const wauthn_const_buffer_s* data);
+    static void deserialize(IStream& stream, wauthn_const_buffer_s** data);
 
     static void serialize(IStream& stream, const wauthn_authenticator_attestation_response_s* data);
     static void deserialize(IStream& stream, wauthn_authenticator_attestation_response_s** data);
@@ -367,8 +367,8 @@ struct Serialization {
     {
         WAuthnCtypeSerializer::serialize(stream, data);
     }
-    // For wauthn_buffer_s
-    static void Serialize(IStream& stream, const wauthn_buffer_s* data)
+    // For wauthn_const_buffer_s
+    static void Serialize(IStream& stream, const wauthn_const_buffer_s* data)
     {
         WAuthnCtypeSerializer::serialize(stream, data);
     }
index f4dd80bad918ad8e1d4aa5b046415833590ea178..bb3c286175ef918d50d51b1f321180bbe90b9134 100644 (file)
@@ -84,4 +84,4 @@ void checkParameters(const wauthn_client_data_s *client_data,
     checkParameters(callbacks);
     checkParameters(options->linked_device, callbacks->qrcode_callback);
 }
-} /* namespace WebAuthn */
\ No newline at end of file
+} /* namespace WebAuthn */
index e9248b15d8fad97f78542d0c80c0f082d68e6599..7549b851e630efcf72c645dbe3210bd645e879d5 100644 (file)
@@ -33,11 +33,11 @@ namespace SerializationTestData {
     unsigned char attestationObjectRaw[16] = {0x11, 0x12, 0x13, 0x14, };
     unsigned char authenticatorDataRaw[26] = {0x21, 0x22, 0x23, 0x24, };
     unsigned char subjectPubkeyInfoRaw[36] = {0x31, 0x32, 0x33, 0x34, };
-    wauthn_buffer_s clientDataJson = {clientDataJsonRaw, sizeof(clientDataJsonRaw)};
-    wauthn_buffer_s attestationObject = {attestationObjectRaw, sizeof(attestationObjectRaw)};
+    wauthn_const_buffer_s clientDataJson = {clientDataJsonRaw, sizeof(clientDataJsonRaw)};
+    wauthn_const_buffer_s attestationObject = {attestationObjectRaw, sizeof(attestationObjectRaw)};
     unsigned int transports = 3;
-    wauthn_buffer_s authenticatorData = {authenticatorDataRaw, sizeof(authenticatorDataRaw)};
-    wauthn_buffer_s subjectPubkeyInfo = {subjectPubkeyInfoRaw, sizeof(subjectPubkeyInfoRaw)};
+    wauthn_const_buffer_s authenticatorData = {authenticatorDataRaw, sizeof(authenticatorDataRaw)};
+    wauthn_const_buffer_s subjectPubkeyInfo = {subjectPubkeyInfoRaw, sizeof(subjectPubkeyInfoRaw)};
     wauthn_cose_algorithm_e pubkey_alg = WAUTHN_COSE_ALGORITHM_ECDSA_P256_WITH_SHA256;
     wauthn_authenticator_attestation_response_s authenticatorAttestationResponse
             = {&clientDataJson, &attestationObject, transports, &authenticatorData, &subjectPubkeyInfo, pubkey_alg};
@@ -46,8 +46,8 @@ namespace SerializationTestData {
 
     unsigned char signatureRaw[26] = {0x21, 0x22, 0x23, 0x24, };
     unsigned char userHandleRaw[36] = {0x31, 0x32, 0x33, 0x34, };
-    wauthn_buffer_s signature = {signatureRaw, sizeof(signatureRaw)};
-    wauthn_buffer_s userHandle = {userHandleRaw, sizeof(userHandleRaw)};
+    wauthn_const_buffer_s signature = {signatureRaw, sizeof(signatureRaw)};
+    wauthn_const_buffer_s userHandle = {userHandleRaw, sizeof(userHandleRaw)};
     wauthn_authenticator_assertion_response_s authenticatorAssertionResponse
             = {&clientDataJson, &authenticatorData, &signature, &userHandle, &attestationObject};
     wauthn_authenticator_assertion_response_s emptyAuthenticatorAssertionResponse
@@ -55,11 +55,11 @@ namespace SerializationTestData {
 
     const char *name = "test name";
     const char *id = "test id";
-    wauthn_rp_entity_s rpEntity = {const_cast<char*>(name), const_cast<char*>(id)};
+    wauthn_rp_entity_s rpEntity = {name, id};
     wauthn_rp_entity_s emptyRpEntiy = {nullptr, nullptr};
 
     unsigned char idRaw[06] = {0x01, 0x02, 0x03, 0x04, };
-    wauthn_buffer_s bufferId = {idRaw, sizeof(idRaw)};
+    wauthn_const_buffer_s bufferId = {idRaw, sizeof(idRaw)};
     const char *displayName = "test displayName";
     wauthn_user_entity_s userEntity = {const_cast<char*>(name), &bufferId, const_cast<char*>(displayName)};
     wauthn_user_entity_s emptyUserEntity = {nullptr, nullptr, nullptr};
@@ -78,8 +78,8 @@ namespace SerializationTestData {
 
     unsigned char idRaw0[06] = {0x01, 0x02, 0x03, 0x04, };
     unsigned char idRaw1[16] = {0x11, 0x12, 0x13, 0x14, };
-    wauthn_buffer_s bufferId0 = {idRaw0, sizeof(idRaw0)};
-    wauthn_buffer_s bufferId1 = {idRaw1, sizeof(idRaw1)};
+    wauthn_const_buffer_s bufferId0 = {idRaw0, sizeof(idRaw0)};
+    wauthn_const_buffer_s bufferId1 = {idRaw1, sizeof(idRaw1)};
     wauthn_pubkey_cred_descriptor_s credDescriptor0 = {pubkeyCredType, &bufferId0, 3};
     wauthn_pubkey_cred_descriptor_s credDescriptor1 = {pubkeyCredType, &bufferId1, 13};
     wauthn_pubkey_cred_descriptor_s pubkeyCredDescriptor2[2] = {credDescriptor0, credDescriptor1};
@@ -92,15 +92,15 @@ namespace SerializationTestData {
 
     unsigned char extensionIdRaw[06] = {0x01, 0x02, 0x03, 0x04, };
     unsigned char extensionValueRaw[16] = {0x11, 0x12, 0x13, 0x14, };
-    wauthn_buffer_s extensionId = {extensionIdRaw, sizeof(extensionIdRaw)};
-    wauthn_buffer_s extensionValue = {extensionValueRaw, sizeof(extensionValueRaw)};
+    wauthn_const_buffer_s extensionId = {extensionIdRaw, sizeof(extensionIdRaw)};
+    wauthn_const_buffer_s extensionValue = {extensionValueRaw, sizeof(extensionValueRaw)};
     wauthn_authentication_ext_s authenticationExt = {&extensionId, &extensionValue};
     wauthn_authentication_ext_s emptyAuthenticationExt = {nullptr, nullptr};
 
     unsigned char extensionIdRaw1[06] = {0x01, 0x02, 0x03, 0x04, };
     unsigned char extensionValueRaw1[16] = {0x11, 0x12, 0x13, 0x14, };
-    wauthn_buffer_s extensionId1 = {extensionIdRaw1, sizeof(extensionIdRaw1)};
-    wauthn_buffer_s extensionValue1 = {extensionValueRaw1, sizeof(extensionValueRaw1)};
+    wauthn_const_buffer_s extensionId1 = {extensionIdRaw1, sizeof(extensionIdRaw1)};
+    wauthn_const_buffer_s extensionValue1 = {extensionValueRaw1, sizeof(extensionValueRaw1)};
     wauthn_authentication_ext_s authenticationExt1 = {&extensionId1, &extensionValue1};
     wauthn_authentication_ext_s authenticationExtArr1[1] = {authenticationExt};
     wauthn_authentication_ext_s authenticationExtArr2[2] = {authenticationExt, authenticationExt1};
@@ -132,13 +132,13 @@ namespace SerializationTestData {
     unsigned char authenticatorNameRaw[26] = {0x11, 0x12, 0x13, 0x14, };
     unsigned char authPubkeyRaw[36] = {0x11, 0x12, 0x13, 0x14, };
     unsigned char tunnelServerDomainRaw[36] = {0x11, 0x12, 0x13, 0x14, };
-    wauthn_buffer_s contactId = {contactIdRaw, sizeof(contactIdRaw)};
-    wauthn_buffer_s linkId = {linkIdRaw, sizeof(linkIdRaw)};
-    wauthn_buffer_s linkSecret = {linkSecretRaw, sizeof(linkSecretRaw)};
-    wauthn_buffer_s authenticatorPubkey = {authenticatorPubkeyRaw, sizeof(authenticatorPubkeyRaw)};
-    wauthn_buffer_s authenticatorName = {authenticatorNameRaw, sizeof(authenticatorNameRaw)};
-    wauthn_buffer_s authPubkey = {authPubkeyRaw, sizeof(authPubkeyRaw)};
-    wauthn_buffer_s tunnelServerDomain = {tunnelServerDomainRaw, sizeof(tunnelServerDomainRaw)};
+    wauthn_const_buffer_s contactId = {contactIdRaw, sizeof(contactIdRaw)};
+    wauthn_const_buffer_s linkId = {linkIdRaw, sizeof(linkIdRaw)};
+    wauthn_const_buffer_s linkSecret = {linkSecretRaw, sizeof(linkSecretRaw)};
+    wauthn_const_buffer_s authenticatorPubkey = {authenticatorPubkeyRaw, sizeof(authenticatorPubkeyRaw)};
+    wauthn_const_buffer_s authenticatorName = {authenticatorNameRaw, sizeof(authenticatorNameRaw)};
+    wauthn_const_buffer_s authPubkey = {authPubkeyRaw, sizeof(authPubkeyRaw)};
+    wauthn_const_buffer_s tunnelServerDomain = {tunnelServerDomainRaw, sizeof(tunnelServerDomainRaw)};
     wauthn_hybrid_linked_data_s hybirdLinkedData = {&contactId, &linkId, &linkSecret, &authenticatorPubkey,
                                 &authenticatorName, &signature, &authPubkey, &tunnelServerDomain};
     wauthn_hybrid_linked_data_s emptyHybirdLinkedData = {nullptr, nullptr, nullptr, nullptr,
@@ -146,10 +146,10 @@ namespace SerializationTestData {
 
     unsigned char bufferRaw0[06] = {0x01, 0x02, 0x03, 0x04, };
     unsigned char bufferRaw1[16] = {0x11, 0x12, 0x13, 0x14, };
-    wauthn_buffer_s buffer0 = {bufferRaw0, sizeof(bufferRaw0)};
-    wauthn_buffer_s buffer1 = {bufferRaw1, sizeof(bufferRaw1)};
-    wauthn_buffer_s attestationFormat1[1] = {buffer0};
-    wauthn_buffer_s attestationFormat2[2] = {buffer0, buffer1};
+    wauthn_const_buffer_s buffer0 = {bufferRaw0, sizeof(bufferRaw0)};
+    wauthn_const_buffer_s buffer1 = {bufferRaw1, sizeof(bufferRaw1)};
+    wauthn_const_buffer_s attestationFormat1[1] = {buffer0};
+    wauthn_const_buffer_s attestationFormat2[2] = {buffer0, buffer1};
     wauthn_attestation_formats_s attestationFormats1 = {sizeof(attestationFormat1)/sizeof(attestationFormat1[0]),
                                                             attestationFormat1};
     wauthn_attestation_formats_s attestationFormats2 = {sizeof(attestationFormat2)/sizeof(attestationFormat2[0]),
@@ -158,7 +158,7 @@ namespace SerializationTestData {
 
     unsigned char challengeRaw[06] = {0x01, 0x02, 0x03, 0x04, };
     unsigned long timeout = 1000;
-    wauthn_buffer_s challenge = {challengeRaw, sizeof(challengeRaw)};
+    wauthn_const_buffer_s challenge = {challengeRaw, sizeof(challengeRaw)};
     wauthn_attestation_pref_e attestation = AP_DIRECT;
     wauthn_pubkey_cred_creation_options_s pubkeyCredCreationOptions = {&rpEntity, &userEntity, &challenge,
             &pubkeyCredParams2, timeout, &pubkeyCredDescriptors2, &authenticatorSelCri, &pubkeyCredHints2,
@@ -291,7 +291,7 @@ void __testDeserializeInvalidMember(T data)
     }
 }
 
-bool __compareWAuthnBuffers(const wauthn_buffer_s *expected, const wauthn_buffer_s *actual)
+bool __compareWAuthnBuffers(const wauthn_const_buffer_s *expected, const wauthn_const_buffer_s *actual)
 {
     if (expected == nullptr || actual == nullptr) {
         return (expected == actual);
@@ -316,7 +316,7 @@ bool __compareCstring(const char *expected, const char *actual)
 void __testUnsignedCharPtr(unsigned char *data, size_t data_size)
 {
     MessageBuffer buffer;
-    unsigned char *deserialized = nullptr;
+    const unsigned char *deserialized = nullptr;
     size_t deserialized_len = 0;
 
     buffer.InitForStreaming();
@@ -372,7 +372,7 @@ TEST_F(WAuthnSerializationTest, unsignedCharPtr_N3)
     // deserialize: for too large data size
     unsigned char data[13] = {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,};
     MessageBuffer buffer;
-    unsigned char *deserialized = nullptr;
+    const unsigned char *deserialized = nullptr;
     size_t deserialized_len = 0;
 
         __fillBufferWithTestData(buffer, MAX_BUFFER_SIZE + 1, data, sizeof(data));
@@ -383,11 +383,11 @@ TEST_F(WAuthnSerializationTest, unsignedCharPtr_N3)
     }
 }
 
-TEST_F(WAuthnSerializationTest, CharPtr_P)
+TEST_F(WAuthnSerializationTest, ConstCharPtr_P)
 {
-    char *data = const_cast<char *>("This is a test data.");
-    char *size0data = const_cast<char *>("");
-    char *nulldata = nullptr;
+    const char *data = "This is a test data.";
+    const char *size0data ="";
+    const char *nulldata = nullptr;
 
     __testSerialization(data, __compareCstring);
     __testSerialization(size0data, __compareCstring);
@@ -401,9 +401,9 @@ TEST_F(WAuthnSerializationTest, CharPtr_N1)
     __testSerializeForInvalidMember(data);
     delete[] data;
 }
-TEST_F(WAuthnSerializationTest, CharPtr_N2)
+TEST_F(WAuthnSerializationTest, ConstCharPtr_N2)
 {// deserialize: for too large length
-    char *deserialized = nullptr;
+    const char *deserialized = nullptr;
     __testDeserializeForTooLongLength(deserialized);
 }
 TEST_F(WAuthnSerializationTest, CharPtr_N3)
@@ -411,7 +411,7 @@ TEST_F(WAuthnSerializationTest, CharPtr_N3)
     // strlen(data) = 4, length in buffer stream = 8
     unsigned char data[8] = {0x01, 0x02, 0x03, 0x04, 0x00, 0x00, 0x00, 0x00};
     MessageBuffer buffer;
-    char *deserialized = nullptr;
+    const char *deserialized = nullptr;
     __fillBufferWithTestData(buffer, sizeof(data), data, sizeof(data));
     try {
         WAuthnCtypeSerializer::deserialize(buffer, &deserialized);
@@ -460,21 +460,21 @@ TEST_F(WAuthnSerializationTest, wauthn_error_e_N2)
 }
 
 
-TEST_F(WAuthnSerializationTest, wauthn_buffer_s_P)
+TEST_F(WAuthnSerializationTest, wauthn_const_buffer_s_P)
 {
     unsigned char testdata[26] = {0x01, 0x02, 0x03, 0x04, };
-    wauthn_buffer_s buffer = {testdata, sizeof(testdata)};
+    wauthn_const_buffer_s buffer = {testdata, sizeof(testdata)};
     __testSerialization(&buffer, __compareWAuthnBuffers);
 
-    wauthn_buffer_s emptyBuffer = {nullptr, 0x00};
+    wauthn_const_buffer_s emptyBuffer = {nullptr, 0x00};
     __testSerialization(&emptyBuffer, __compareWAuthnBuffers);
 
-    __testSerialization(static_cast<wauthn_buffer_s *>(nullptr), __compareWAuthnBuffers);
+    __testSerialization(static_cast<wauthn_const_buffer_s *>(nullptr), __compareWAuthnBuffers);
 }
-TEST_F(WAuthnSerializationTest, wauthn_buffer_s_N1)
+TEST_F(WAuthnSerializationTest, wauthn_const_buffer_s_N1)
 {// serialize: for too large length
     unsigned char testdata[26] = {0x01, 0x02, 0x03, 0x04, };
-    wauthn_buffer_s data = {testdata, MAX_BUFFER_SIZE + 1};
+    wauthn_const_buffer_s data = {testdata, MAX_BUFFER_SIZE + 1};
     MessageBuffer buffer;
     buffer.InitForStreaming();
     try {
@@ -483,10 +483,10 @@ TEST_F(WAuthnSerializationTest, wauthn_buffer_s_N1)
     } catch(SerializationException::InvalidStreamData &) {
     }
 }
-TEST_F(WAuthnSerializationTest, wauthn_buffer_s_N2)
+TEST_F(WAuthnSerializationTest, wauthn_const_buffer_s_N2)
 {// serialize: for inconsistent pointer & length
     unsigned char testdata[26] = {0x01, 0x02, 0x03, 0x04, };
-    wauthn_buffer_s data = {nullptr, sizeof(testdata)};
+    wauthn_const_buffer_s data = {nullptr, sizeof(testdata)};
     MessageBuffer buffer;
     buffer.InitForStreaming();
     try {
@@ -495,9 +495,9 @@ TEST_F(WAuthnSerializationTest, wauthn_buffer_s_N2)
     } catch(SerializationException::InvalidStreamData &) {
     }
 }
-TEST_F(WAuthnSerializationTest, wauthn_buffer_s_N3)
+TEST_F(WAuthnSerializationTest, wauthn_const_buffer_s_N3)
 {// deserialize: for too large length
-    wauthn_buffer_s *deserialized = nullptr;
+    wauthn_const_buffer_s *deserialized = nullptr;
     __testDeserializeForTooLongLength(deserialized);
 }
 
@@ -1357,4 +1357,4 @@ TEST_F(WAuthnSerializationTest, multiple_serialization_gares_P)
 }
 
 
-} // namespace WA
\ No newline at end of file
+} // namespace WA
index 15e2177a1ba3a713308a1bed1d8bc6199ef66169..1382d4412f4f53393ecc4b1283645a3cf91dd60c 100644 (file)
@@ -36,11 +36,11 @@ namespace CommonTestData {
     unsigned char attestationObjectRaw[16] = {0x11, 0x12, 0x13, 0x14, };
     unsigned char authenticatorDataRaw[26] = {0x21, 0x22, 0x23, 0x24, };
     unsigned char subjectPubkeyInfoRaw[36] = {0x31, 0x32, 0x33, 0x34, };
-    wauthn_buffer_s clientDataJson = {clientDataJsonRaw, sizeof(clientDataJsonRaw)};
-    wauthn_buffer_s attestationObject = {attestationObjectRaw, sizeof(attestationObjectRaw)};
+    wauthn_const_buffer_s clientDataJson = {clientDataJsonRaw, sizeof(clientDataJsonRaw)};
+    wauthn_const_buffer_s attestationObject = {attestationObjectRaw, sizeof(attestationObjectRaw)};
     unsigned int transports = 3;
-    wauthn_buffer_s authenticatorData = {authenticatorDataRaw, sizeof(authenticatorDataRaw)};
-    wauthn_buffer_s subjectPubkeyInfo = {subjectPubkeyInfoRaw, sizeof(subjectPubkeyInfoRaw)};
+    wauthn_const_buffer_s authenticatorData = {authenticatorDataRaw, sizeof(authenticatorDataRaw)};
+    wauthn_const_buffer_s subjectPubkeyInfo = {subjectPubkeyInfoRaw, sizeof(subjectPubkeyInfoRaw)};
     wauthn_cose_algorithm_e pubkey_alg = WAUTHN_COSE_ALGORITHM_ECDSA_P256_WITH_SHA256;
     wauthn_authenticator_attestation_response_s authenticatorAttestationResponse
             = {&clientDataJson, &attestationObject, transports, &authenticatorData, &subjectPubkeyInfo, pubkey_alg};
@@ -49,8 +49,8 @@ namespace CommonTestData {
 
     unsigned char signatureRaw[26] = {0x21, 0x22, 0x23, 0x24, };
     unsigned char userHandleRaw[36] = {0x31, 0x32, 0x33, 0x34, };
-    wauthn_buffer_s signature = {signatureRaw, sizeof(signatureRaw)};
-    wauthn_buffer_s userHandle = {userHandleRaw, sizeof(userHandleRaw)};
+    wauthn_const_buffer_s signature = {signatureRaw, sizeof(signatureRaw)};
+    wauthn_const_buffer_s userHandle = {userHandleRaw, sizeof(userHandleRaw)};
     wauthn_authenticator_assertion_response_s authenticatorAssertionResponse
             = {&clientDataJson, &authenticatorData, &signature, &userHandle, &attestationObject};
     wauthn_authenticator_assertion_response_s emptyAuthenticatorAssertionResponse
@@ -58,11 +58,11 @@ namespace CommonTestData {
 
     const char *name = "test name";
     const char *id = "test id";
-    wauthn_rp_entity_s rpEntity = {const_cast<char*>(name), const_cast<char*>(id)};
+    wauthn_rp_entity_s rpEntity = {name, id};
     wauthn_rp_entity_s emptyRpEntiy = {nullptr, nullptr};
 
     unsigned char idRaw[06] = {0x01, 0x02, 0x03, 0x04, };
-    wauthn_buffer_s bufferId = {idRaw, sizeof(idRaw)};
+    wauthn_const_buffer_s bufferId = {idRaw, sizeof(idRaw)};
     const char *displayName = "test displayName";
     wauthn_user_entity_s userEntity = {const_cast<char*>(name), &bufferId, const_cast<char*>(displayName)};
     wauthn_user_entity_s emptyUserEntity = {nullptr, nullptr, nullptr};
@@ -81,8 +81,8 @@ namespace CommonTestData {
 
     unsigned char idRaw0[06] = {0x01, 0x02, 0x03, 0x04, };
     unsigned char idRaw1[16] = {0x11, 0x12, 0x13, 0x14, };
-    wauthn_buffer_s bufferId0 = {idRaw0, sizeof(idRaw0)};
-    wauthn_buffer_s bufferId1 = {idRaw1, sizeof(idRaw1)};
+    wauthn_const_buffer_s bufferId0 = {idRaw0, sizeof(idRaw0)};
+    wauthn_const_buffer_s bufferId1 = {idRaw1, sizeof(idRaw1)};
     wauthn_pubkey_cred_descriptor_s credDescriptor0 = {pubkeyCredType, &bufferId0, 3};
     wauthn_pubkey_cred_descriptor_s credDescriptor1 = {pubkeyCredType, &bufferId1, 13};
     wauthn_pubkey_cred_descriptor_s pubkeyCredDescriptor2[2] = {credDescriptor0, credDescriptor1};
@@ -95,15 +95,15 @@ namespace CommonTestData {
 
     unsigned char extensionIdRaw[06] = {0x01, 0x02, 0x03, 0x04, };
     unsigned char extensionValueRaw[16] = {0x11, 0x12, 0x13, 0x14, };
-    wauthn_buffer_s extensionId = {extensionIdRaw, sizeof(extensionIdRaw)};
-    wauthn_buffer_s extensionValue = {extensionValueRaw, sizeof(extensionValueRaw)};
+    wauthn_const_buffer_s extensionId = {extensionIdRaw, sizeof(extensionIdRaw)};
+    wauthn_const_buffer_s extensionValue = {extensionValueRaw, sizeof(extensionValueRaw)};
     wauthn_authentication_ext_s authenticationExt = {&extensionId, &extensionValue};
     wauthn_authentication_ext_s emptyAuthenticationExt = {nullptr, nullptr};
 
     unsigned char extensionIdRaw1[06] = {0x01, 0x02, 0x03, 0x04, };
     unsigned char extensionValueRaw1[16] = {0x11, 0x12, 0x13, 0x14, };
-    wauthn_buffer_s extensionId1 = {extensionIdRaw1, sizeof(extensionIdRaw1)};
-    wauthn_buffer_s extensionValue1 = {extensionValueRaw1, sizeof(extensionValueRaw1)};
+    wauthn_const_buffer_s extensionId1 = {extensionIdRaw1, sizeof(extensionIdRaw1)};
+    wauthn_const_buffer_s extensionValue1 = {extensionValueRaw1, sizeof(extensionValueRaw1)};
     wauthn_authentication_ext_s authenticationExt1 = {&extensionId1, &extensionValue1};
     wauthn_authentication_ext_s authenticationExtArr1[1] = {authenticationExt};
     wauthn_authentication_ext_s authenticationExtArr2[2] = {authenticationExt, authenticationExt1};
@@ -135,13 +135,13 @@ namespace CommonTestData {
     unsigned char authenticatorNameRaw[26] = {0x11, 0x12, 0x13, 0x14, };
     unsigned char authPubkeyRaw[36] = {0x11, 0x12, 0x13, 0x14, };
     unsigned char tunnelServerDomainRaw[36] = {0x11, 0x12, 0x13, 0x14, };
-    wauthn_buffer_s contactId = {contactIdRaw, sizeof(contactIdRaw)};
-    wauthn_buffer_s linkId = {linkIdRaw, sizeof(linkIdRaw)};
-    wauthn_buffer_s linkSecret = {linkSecretRaw, sizeof(linkSecretRaw)};
-    wauthn_buffer_s authenticatorPubkey = {authenticatorPubkeyRaw, sizeof(authenticatorPubkeyRaw)};
-    wauthn_buffer_s authenticatorName = {authenticatorNameRaw, sizeof(authenticatorNameRaw)};
-    wauthn_buffer_s authPubkey = {authPubkeyRaw, sizeof(authPubkeyRaw)};
-    wauthn_buffer_s tunnelServerDomain = {tunnelServerDomainRaw, sizeof(tunnelServerDomainRaw)};
+    wauthn_const_buffer_s contactId = {contactIdRaw, sizeof(contactIdRaw)};
+    wauthn_const_buffer_s linkId = {linkIdRaw, sizeof(linkIdRaw)};
+    wauthn_const_buffer_s linkSecret = {linkSecretRaw, sizeof(linkSecretRaw)};
+    wauthn_const_buffer_s authenticatorPubkey = {authenticatorPubkeyRaw, sizeof(authenticatorPubkeyRaw)};
+    wauthn_const_buffer_s authenticatorName = {authenticatorNameRaw, sizeof(authenticatorNameRaw)};
+    wauthn_const_buffer_s authPubkey = {authPubkeyRaw, sizeof(authPubkeyRaw)};
+    wauthn_const_buffer_s tunnelServerDomain = {tunnelServerDomainRaw, sizeof(tunnelServerDomainRaw)};
     wauthn_hybrid_linked_data_s hybirdLinkedData = {&contactId, &linkId, &linkSecret, &authenticatorPubkey,
                                 &authenticatorName, &signature, &authPubkey, &tunnelServerDomain};
     wauthn_hybrid_linked_data_s emptyHybirdLinkedData = {nullptr, nullptr, nullptr, nullptr,
@@ -149,10 +149,10 @@ namespace CommonTestData {
 
     unsigned char bufferRaw0[06] = {0x01, 0x02, 0x03, 0x04, };
     unsigned char bufferRaw1[16] = {0x11, 0x12, 0x13, 0x14, };
-    wauthn_buffer_s buffer0 = {bufferRaw0, sizeof(bufferRaw0)};
-    wauthn_buffer_s buffer1 = {bufferRaw1, sizeof(bufferRaw1)};
-    wauthn_buffer_s attestationFormat1[1] = {buffer0};
-    wauthn_buffer_s attestationFormat2[2] = {buffer0, buffer1};
+    wauthn_const_buffer_s buffer0 = {bufferRaw0, sizeof(bufferRaw0)};
+    wauthn_const_buffer_s buffer1 = {bufferRaw1, sizeof(bufferRaw1)};
+    wauthn_const_buffer_s attestationFormat1[1] = {buffer0};
+    wauthn_const_buffer_s attestationFormat2[2] = {buffer0, buffer1};
     wauthn_attestation_formats_s attestationFormats1 = {sizeof(attestationFormat1)/sizeof(attestationFormat1[0]),
                                                             attestationFormat1};
     wauthn_attestation_formats_s attestationFormats2 = {sizeof(attestationFormat2)/sizeof(attestationFormat2[0]),
@@ -161,7 +161,7 @@ namespace CommonTestData {
 
     unsigned char challengeRaw[06] = {0x01, 0x02, 0x03, 0x04, };
     unsigned long timeout = 1000;
-    wauthn_buffer_s challenge = {challengeRaw, sizeof(challengeRaw)};
+    wauthn_const_buffer_s challenge = {challengeRaw, sizeof(challengeRaw)};
     wauthn_attestation_pref_e attestation = AP_DIRECT;
     wauthn_pubkey_cred_creation_options_s pubkeyCredCreationOptions = {&rpEntity, &userEntity, &challenge,
             &pubkeyCredParams2, timeout, &pubkeyCredDescriptors2, &authenticatorSelCri, &pubkeyCredHints2,
@@ -401,4 +401,4 @@ TEST_F(WebAuthnTest, testCancelOK)
     sleep(10);
 }
 
-} // namespace WA
\ No newline at end of file
+} // namespace WA