Add Write\ReadBinaryKey to sample

This commit is contained in:
Jim Norman 2006-09-29 19:02:07 +00:00
parent 076e2c0650
commit 6eb95d8fbd

View File

@ -198,6 +198,80 @@ void ReadKey()
}
void ReadBinaryKey()
{
int rcode = 0;
char inputID[20];
char inputKey[20];
char inputValue[128] = {0};
uint32_t valueLen = 128;
uint32_t bytesRequired = 0;
SSCS_SECRETSTORE_T store = {0};
SSCS_SECRET_ID_T appSecretId = {0};
SSCS_SECRET_ID_T sharedSecretId = {0};
void *context;
SSCS_KEYCHAIN_ID_T kc = {0};
SSCS_EXT_T ext = {0};
printf("Enter secretID: ");
gets(inputID);
printf("Enter Key: ");
gets(inputKey);
if ((sscs_Utf8Strlen(inputID) > 0) &&
(sscs_Utf8Strlen(inputKey) > 0))
{
appSecretId.len = sscs_Utf8Strlen(inputID) + 1;
sscs_Utf8Strcpy(appSecretId.id, inputID);
printf("SAMPLE: Calling miCASAReadKey\r\n");
// open secretStore
sscs_Utf8Strcpy(store.ssName, SSCS_DEFAULT_SECRETSTORE_ID);
store.version = 1;
context = miCASAOpenSecretStoreCache(&store, 0, NULL);
if (context == NULL)
{
return; // NSSCS_E_SYSTEM_FAILURE;
}
sscs_Utf8Strcpy(kc.keychainID, SSCS_SESSION_KEY_CHAIN_ID);
kc.len = SSCS_S_KC_ID_CHARS;
rcode = miCASAReadBinaryKey(context,
0,
&kc,
&appSecretId,
inputKey,
strlen(inputKey)+1,
inputValue,
&valueLen,
NULL,
&bytesRequired,
&ext);
miCASACloseSecretStoreCache(context, 0, NULL);
if (rcode)
{
printf("miCASAReadKey returned %d\r\n", rcode);
Pause();
}
else
{
//set null
//memcpy(inputValue[valueLen + 1],
printf("KeyValue is %s\r\n", inputValue);
}
}
}
void WriteKey()
{
int rcode = 0;
@ -265,6 +339,76 @@ void WriteKey()
}
}
void WriteBinaryKey()
{
int rcode = 0;
char inputID[20];
char inputKey[20];
char inputValue[20];
uint32_t valueLen = 0;
SSCS_SECRETSTORE_T store = {0};
SSCS_SECRET_ID_T appSecretId = {0};
SSCS_SECRET_ID_T sharedSecretId = {0};
void *context;
SSCS_KEYCHAIN_ID_T kc = {0};
SSCS_EXT_T ext = {0};
printf("Enter secretID: ");
gets(inputID);
printf("Enter Key: ");
gets(inputKey);
printf("Enter Value: ");
gets(inputValue);
if ((sscs_Utf8Strlen(inputID) > 0) &&
(sscs_Utf8Strlen(inputKey) > 0) &&
(sscs_Utf8Strlen(inputValue) > 0))
{
appSecretId.len = sscs_Utf8Strlen(inputID) + 1;
sscs_Utf8Strcpy(appSecretId.id, inputID);
printf("SAMPLE: Calling miCASAWriteKey\r\n");
// open secretStore
sscs_Utf8Strcpy(store.ssName, SSCS_DEFAULT_SECRETSTORE_ID);
store.version = 1;
context = miCASAOpenSecretStoreCache(&store, 0, NULL);
if (context == NULL)
{
return; // NSSCS_E_SYSTEM_FAILURE;
}
sscs_Utf8Strcpy(kc.keychainID, SSCS_SESSION_KEY_CHAIN_ID);
kc.len = SSCS_S_KC_ID_CHARS;
valueLen = sscs_strlen(inputValue) + 1;
miCASAWriteBinaryKey(context,
0,
&kc,
&appSecretId,
inputKey,
strlen(inputKey)+1,
inputValue,
&valueLen,
NULL,
&ext);
miCASACloseSecretStoreCache(context, 0, NULL);
if (rcode)
{
printf("miCASAWriteKey returned %d\r\n", rcode);
Pause();
}
}
}
void AddSecret()
{
int rcode = 0;
@ -614,7 +758,9 @@ void displayMenu()
printf("* 5. WriteKey *\r\n");
printf("* 6. ReadKey *\r\n");
printf("* 7. RemoveKey *\r\n");
printf("* 8. Quit *\r\n");
printf("* 8. WriteBinaryKey *\r\n");
printf("* 9. ReadBinaryKey *\r\n");
printf("* Q. Quit *\r\n");
printf("**************************\r\n");
@ -624,7 +770,7 @@ void displayMenu()
// get return
getchar();
if (c == '8')
if ((c == 'Q') || (c == 'q'))
return;
else if (c == '1')
AddSecret();
@ -640,6 +786,10 @@ void displayMenu()
ReadKey();
else if (c == '7')
RemoveKey();
else if (c == '8')
WriteBinaryKey();
else if (c == '9')
ReadBinaryKey();
}