quickjs-tart

quickjs-based runtime for wallet-core logic
Log | Files | Refs | README | LICENSE

client.c (1345B)


      1 /* psasim test client */
      2 
      3 /*
      4  *  Copyright The Mbed TLS Contributors
      5  *  SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
      6  */
      7 
      8 #include <psa/client.h>
      9 #include "psa_manifest/sid.h"
     10 #include <stdio.h>
     11 #include <unistd.h>
     12 
     13 int main()
     14 {
     15 
     16     const char *text = "FOOBARCOOL!!";
     17 
     18     char output[100] = { 0 };
     19     printf("My PID is %d\n", getpid());
     20 
     21     printf("The version of the service is %u\n", psa_version(PSA_SID_SHA256_SID));
     22     psa_handle_t h = psa_connect(PSA_SID_SHA256_SID, 1);
     23 
     24     if (h < 0) {
     25         printf("Couldn't connect %d\n", h);
     26         return 1;
     27     } else {
     28         int type = 2;
     29         puts("Calling!");
     30         puts("Trying without invec");
     31         printf("Answer to my call was %d (no invec)\n", psa_call(h, type, NULL, 0, NULL, 0));
     32         psa_invec invecs[1];
     33         psa_outvec outvecs[1];
     34         invecs[0].base = text;
     35         invecs[0].len = 24;
     36         outvecs[0].base = output;
     37         outvecs[0].len = 99;
     38 
     39         printf("My iovec size should be %lu\n", invecs[0].len);
     40         printf("Answer to my call was %d (with invec)\n", psa_call(h, type, invecs, 1, outvecs, 1));
     41         printf("Here's the payload I recieved: %s\n", output);
     42         printf("Apparently the server wrote %lu bytes in outvec %d\n", outvecs[0].len, 0);
     43         puts("Closing handle");
     44         psa_close(h);
     45     }
     46 
     47     return 0;
     48 }