keygen/src/iam.c
/**
 * iam_new_ep_auth_network() - Created a new request for XIAM endpoint request
 * @network: The IPv6 subnet being requested
 * @key: The x9.62-encoded public key
 * @req Address to write the returned data into
 *
 * Returned value must be freed with iam_destroy
 *
 * Return: 1 on success, 0 on failure
 */
Created a new request for XIAM endpoint request
@network: The IPv6 subnet being requested
@key: The x9.62-encoded public key
@req Address to write the returned data into

Returned value must be freed with iam_destroy

1 on success, 0 on failure
Created a new request for XIAM endpoint request @network : The IPv6 subnet being requested @key : The x9 . 62 - encoded public key @req Address to write the returned data into Returned value must be freed with iam_destroy 1 on success 0 on failure
int iam_new_ep_auth_network_request(char *network, char *key, struct iam_create_endpoint_request *request)
{
    int ret = 1;
    enum addr_type addr_type;
    if (strlen(network) + 1 > sizeof(request->endpoint)) {
        fprintf(stderr, "Error: Endpoint address too long.");
        ret = 0;
        goto out;
    }
    request->ecdsa_credential.key = malloc(strlen(key) + 1);
    if (!request->ecdsa_credential.key) {
        fprintf(stderr, "%s ERR: Memory alloc failed for key.", __func__);
        ret = 0;
        goto cleanup;
    }
    strcpy(request->ecdsa_credential.key, key);
    strcpy(request->ecdsa_credential.type, type_ecdsa_p256);
    strcpy(request->endpoint, network);
    addr_type = ip_version(network);
    if (addr_type == TYPE_IPV6_NETWORK) {
        request->type = NETWORK;
    } else if(addr_type == TYPE_IPV6_ADDR) {
        request->type = ADDRESS;
        char * slash;
        slash = strchr(request->endpoint, '/');
        if (slash)
            *slash = '\0';
    } else {
        fprintf(stderr, "Error: Cannot parse address as an IPv6 address or ::/64 network.\n");
        ret = 0;
        goto cleanup;
    }
    goto out;
cleanup:
    free(request->ecdsa_credential.key);
    request->ecdsa_credential.key = NULL;
out:
    return ret;
}
int iam_new_ep_auth_network_request ( char * network , char * key , struct iam_create_endpoint_request * request ) { int ret = 1 ; enum addr_type addr_type ; if ( strlen ( network ) + 1 > sizeof ( request -> endpoint ) ) { fprintf ( stderr , " " ) ; ret = 0 ; goto out ; } request -> ecdsa_credential . key = malloc ( strlen ( key ) + 1 ) ; if ( ! request -> ecdsa_credential . key ) { fprintf ( stderr , " " , __func__ ) ; ret = 0 ; goto cleanup ; } strcpy ( request -> ecdsa_credential . key , key ) ; strcpy ( request -> ecdsa_credential . type , type_ecdsa_p256 ) ; strcpy ( request -> endpoint , network ) ; addr_type = ip_version ( network ) ; if ( addr_type == TYPE_IPV6_NETWORK ) { request -> type = NETWORK ; } else if ( addr_type == TYPE_IPV6_ADDR ) { request -> type = ADDRESS ; char * slash ; slash = strchr ( request -> endpoint , ' ' ) ; if ( slash ) * slash = ' \0 ' ; } else { fprintf ( stderr , " \n " ) ; ret = 0 ; goto cleanup ; } goto out ; cleanup : free ( request -> ecdsa_credential . key ) ; request -> ecdsa_credential . key = NULL ; out : return ret ; }
iam_new_ep_auth_network() - Created a new request for XIAM endpoint request
 @network: The IPv6 subnet being requested
 @key: The x9.62-encoded public key
 @req Address to write the returned data into
iam_new_ep_auth_network () - Created a new request for XIAM endpoint request @network : The IPv6 subnet being requested @key : The x9 . 62 - encoded public key @req Address to write the returned data into
/* Avoid an overcopy error */ /* Allocate and copy the key */ /* Note: The API does not accept ::/128 at this time so convert this "subnet" to a regular address */ /* Success */