Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: EthernetInterface NTPClient iothub_amqp_transport iothub_client mbed-rtos mbed
Fork of iothub_client_sample_amqp by
sasl_anonymous.c
00001 // Copyright (c) Microsoft. All rights reserved. 00002 // Licensed under the MIT license. See LICENSE file in the project root for full license information. 00003 00004 #include <stdlib.h> 00005 #ifdef _CRTDBG_MAP_ALLOC 00006 #include <crtdbg.h> 00007 #endif 00008 #include <string.h> 00009 #include "azure_uamqp_c/sasl_anonymous.h" 00010 #include "azure_uamqp_c/amqpalloc.h" 00011 #include "azure_c_shared_utility/xlogging.h" 00012 00013 typedef struct SASL_ANONYMOUS_INSTANCE_TAG 00014 { 00015 unsigned char dummy; 00016 } SASL_ANONYMOUS_INSTANCE; 00017 00018 /* Codes_SRS_SASL_ANONYMOUS_01_010: [saslanonymous_get_interface shall return a pointer to a SASL_MECHANISM_INTERFACE_DESCRIPTION structure that contains pointers to the functions: saslanonymous_create, saslanonymous_destroy, saslanonymous_get_init_bytes, saslanonymous_get_mechanism_name, saslanonymous_challenge.] */ 00019 static const SASL_MECHANISM_INTERFACE_DESCRIPTION saslanonymous_interface = 00020 { 00021 saslanonymous_create, 00022 saslanonymous_destroy, 00023 saslanonymous_get_init_bytes, 00024 saslanonymous_get_mechanism_name, 00025 saslanonymous_challenge 00026 }; 00027 00028 /* Codes_SRS_SASL_ANONYMOUS_01_001: [saslanonymous_create shall return on success a non-NULL handle to a new SASL anonymous mechanism.] */ 00029 CONCRETE_SASL_MECHANISM_HANDLE saslanonymous_create(void* config) 00030 { 00031 /* Codes_SRS_SASL_ANONYMOUS_01_003: [Since this is the ANONYMOUS SASL mechanism, config shall be ignored.] */ 00032 (void)config; 00033 00034 /* Codes_SRS_SASL_ANONYMOUS_01_002: [If allocating the memory needed for the saslanonymous instance fails then saslanonymous_create shall return NULL.] */ 00035 return amqpalloc_malloc(sizeof(SASL_ANONYMOUS_INSTANCE)); 00036 } 00037 00038 void saslanonymous_destroy(CONCRETE_SASL_MECHANISM_HANDLE sasl_mechanism_concrete_handle) 00039 { 00040 /* Codes_SRS_SASL_ANONYMOUS_01_005: [If the argument concrete_sasl_mechanism is NULL, saslanonymous_destroy shall do nothing.] */ 00041 if (sasl_mechanism_concrete_handle != NULL) 00042 { 00043 /* Codes_SRS_SASL_ANONYMOUS_01_004: [saslanonymous_destroy shall free all resources associated with the SASL mechanism.] */ 00044 amqpalloc_free(sasl_mechanism_concrete_handle); 00045 } 00046 } 00047 00048 int saslanonymous_get_init_bytes(CONCRETE_SASL_MECHANISM_HANDLE sasl_mechanism_concrete_handle, SASL_MECHANISM_BYTES* init_bytes) 00049 { 00050 int result; 00051 00052 /* Codes_SRS_SASL_ANONYMOUS_01_007: [If the any argument is NULL, saslanonymous_get_init_bytes shall return a non-zero value.] */ 00053 if ((sasl_mechanism_concrete_handle == NULL) || 00054 (init_bytes == NULL)) 00055 { 00056 result = __LINE__; 00057 } 00058 else 00059 { 00060 /* Codes_SRS_SASL_ANONYMOUS_01_012: [The bytes field of init_buffer shall be set to NULL.] */ 00061 init_bytes->bytes = NULL; 00062 /* Codes_SRS_SASL_ANONYMOUS_01_006: [saslanonymous_get_init_bytes shall validate the concrete_sasl_mechanism argument and set the length of the init_bytes argument to be zero.] */ 00063 init_bytes->length = 0; 00064 00065 /* Codes_SRS_SASL_ANONYMOUS_01_011: [On success saslanonymous_get_init_bytes shall return zero.] */ 00066 result = 0; 00067 } 00068 00069 return result; 00070 } 00071 00072 const char* saslanonymous_get_mechanism_name(CONCRETE_SASL_MECHANISM_HANDLE sasl_mechanism) 00073 { 00074 const char* result; 00075 00076 /* Codes_SRS_SASL_ANONYMOUS_01_009: [If the argument concrete_sasl_mechanism is NULL, saslanonymous_get_mechanism_name shall return NULL.] */ 00077 if (sasl_mechanism == NULL) 00078 { 00079 result = NULL; 00080 } 00081 else 00082 { 00083 /* Codes_SRS_SASL_ANONYMOUS_01_008: [saslanonymous_get_mechanism_name shall validate the argument concrete_sasl_mechanism and on success it shall return a pointer to the string "ANONYMOUS".] */ 00084 result = "ANONYMOUS"; 00085 } 00086 00087 return result; 00088 } 00089 00090 int saslanonymous_challenge(CONCRETE_SASL_MECHANISM_HANDLE concrete_sasl_mechanism, const SASL_MECHANISM_BYTES* challenge_bytes, SASL_MECHANISM_BYTES* response_bytes) 00091 { 00092 int result; 00093 00094 (void)challenge_bytes; 00095 00096 /* Codes_SRS_SASL_ANONYMOUS_01_015: [If the concrete_sasl_mechanism or response_bytes argument is NULL then saslanonymous_challenge shall fail and return a non-zero value.] */ 00097 if ((concrete_sasl_mechanism == NULL) || 00098 (response_bytes == NULL)) 00099 { 00100 result = __LINE__; 00101 } 00102 else 00103 { 00104 /* Codes_SRS_SASL_ANONYMOUS_01_013: [saslanonymous_challenge shall set the response_bytes buffer to NULL and 0 size as the ANONYMOUS SASL mechanism does not implement challenge/response.] */ 00105 response_bytes->bytes = NULL; 00106 response_bytes->length = 0; 00107 00108 /* Codes_SRS_SASL_ANONYMOUS_01_014: [On success, saslanonymous_challenge shall return 0.] */ 00109 result = 0; 00110 } 00111 00112 return result; 00113 } 00114 00115 const SASL_MECHANISM_INTERFACE_DESCRIPTION* saslanonymous_get_interface(void) 00116 { 00117 return &saslanonymous_interface; 00118 }
Generated on Tue Jul 12 2022 12:43:22 by
