⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 defaultstorageprov.c

📁 IBE是一种非对称密码技术
💻 C
📖 第 1 页 / 共 5 页
字号:

  /* If this function was called by the VtStorageImplNull 
   * simply return Vt_ERROR_NO_STORAGE_PROVIDER_LOADED
   */
  if (ctx->providerNum == -2)
    return (VT_ERROR_NO_STORAGE_PROVIDER_LOADED);

  qualName = (unsigned char *)0;
  unqualName = (unsigned char *)0;

  *count = 0;
  do
  {
    if (reference != (VtDistrictObject)0)
    {
      qualName = obj->qualDistrictName.data;
      unqualName = obj->unqualDistrictName.data;
    }

    /* If there's no reference, return the count of all parameter sets.
     */
    if (qualName == (unsigned char *)0)
    {
      /* If an unqualified name is given, but no qualified name, this
       * provider can't return a count.
       */
      VOLT_SET_ERROR_TYPE (errorType, VT_ERROR_TYPE_PRIMARY)
      VOLT_SET_FNCT_LINE (fnctLine)
      status = VT_ERROR_INVALID_STORAGE_REF;
      if (unqualName != (unsigned char *)0)
        break;

      VOLT_SET_ERROR_TYPE (errorType, 0)
      VOLT_SET_FNCT_LINE (fnctLine)
      status = VoltGetStorageFileListAlloc (
        ctx, VOLT_STORE_DIR_DIST_PARAMS, VOLT_STORE_DIR_DIST_PARAMS_LEN, 0,
        &nameList);
      if (status != 0)
        break;

      if (nameList != (VtFileNameList *)0)
        *count = nameList->nameCount;

      break;
    }

    /* Build a temp object to manipulate, we don't want to mess with
     * the reference.
     */
    VOLT_SET_ERROR_TYPE (errorType, 0)
    VOLT_SET_FNCT_LINE (fnctLine)
    status = VtCreateDistrictObject (
      obj->voltObject.libraryCtx, obj->DistrictImpl, obj->distImplInfo,
      &tempObject);
    if (status != 0)
      break;

    VOLT_SET_FNCT_LINE (fnctLine)
    status = VtSetDistrictParam (
      tempObject, VtDistrictParamQualifiedName,
      (Pointer)(obj->qualDistrictName.data));
    if (status != 0)
      break;

    /* Try to load the params.
     */
    VOLT_SET_FNCT_LINE (fnctLine)
    status = VoltDefaultRetrieveDistrictParameters (
      storageCtx, tempObject, 0, &timeOfStore);

    /* If the Retrieve call succeeded, the parameter count is 1.
     */
    if (status == 0)
    {
      *count = 1;
      break;
    }

    /* There's an error, if it is VT_ERROR_UNKNOWN_DISTRICT, the count
     * is 0 and we don't want to pass on the error. Any other error
     * pass on.
     */
    if (status == VT_ERROR_UNKNOWN_DISTRICT)
      status = 0;

  } while (0);

  VtDestroyDistrictObject (&tempObject);
  if (nameList != (VtFileNameList *)0)
    VoltFileListFree (libCtx, &nameList);

  if (status == 0)
    return 0;

  VOLT_LOG_ERROR (
    (VtLibCtx)libCtx, status, errorType, fnctLine,
    "VoltDefaultGetDistrictParameterCount", (char *)0)

  return (status);
}

int VoltGetEntryCountFromIdentity (
   VtStorageCtx storageCtx,
   VtIdentityObject reference,
   unsigned int *count,
   unsigned char *directory,
   unsigned int directoryLen,
   unsigned int valueType
   )
{
  int status;
  unsigned int fileNameLen;
  VoltStorageCtx *ctx = (VoltStorageCtx *)storageCtx;
  VoltLibCtx *libCtx = (VoltLibCtx *)(ctx->voltObject.libraryCtx);
  VoltDefaultStorageCtx *defStorageCtx =
    (VoltDefaultStorageCtx *)(ctx->localStorageCtx);
  VoltFileCtx *fileCtx = (VoltFileCtx *)0;
  VoltIdentityObject *idObj;
  VtFileNameList *nameList = (VtFileNameList *)0;
  unsigned char *fileName = (unsigned char *)0;
  VoltFileHandle fileHandle = (VoltFileHandle)0;
  VOLT_DECLARE_FNCT_LINE (fnctLine)
  VOLT_DECLARE_ERROR_TYPE (errorType) 

  /* If this function was called by the VtStorageImplNull 
   * simply return Vt_ERROR_NO_STORAGE_PROVIDER_LOADED
   */
  if (ctx->providerNum == -2)
    return VT_ERROR_NO_STORAGE_PROVIDER_LOADED;

  fileCtx = (VoltFileCtx *)defStorageCtx->fCtx;
  *count = 0;
  do
  {
    /* If there's no reference, just get all private keys.
     */
    if (reference == (VtIdentityObject)0)
    {
      VOLT_SET_ERROR_TYPE (errorType, 0)
      VOLT_SET_FNCT_LINE (fnctLine)
      status = VoltGetStorageFileListAlloc (
        ctx, directory, directoryLen, 0, &nameList);
      if (status != 0)
        break;

      if (nameList != (VtFileNameList *)0)
        *count = nameList->nameCount;

      break;
    }

    /* If there is a reference, this implementation requires an encoded
     * ID.
     */
    VOLT_SET_ERROR_TYPE (errorType, VT_ERROR_TYPE_PRIMARY)
    VOLT_SET_FNCT_LINE (fnctLine)
    status = VT_ERROR_INVALID_STORAGE_REF;
    idObj = (VoltIdentityObject *)reference;
    if (idObj->encoding.data == (unsigned char *)0)
      break;

    /* Get the file name.
     */
    VOLT_SET_ERROR_TYPE (errorType, 0)
    VOLT_SET_FNCT_LINE (fnctLine)
    status = VoltGetFileNameFromValueAlloc (
      ctx, (unsigned char *)0, 0, idObj->encoding.data, idObj->encoding.len,
      valueType, &fileName, &fileNameLen);
    if (status != 0)
      break;

    /* Try to open this file.
     */
    VOLT_SET_FNCT_LINE (fnctLine)
    status = fileCtx->CtxOpenFile (
      fileCtx, &fileHandle, fileName, VOLT_FILE_MODE_READ_ONLY, 0);

    /* If the file opened, there is one private key. If not, there is 0.
     */
    if (status == 0)
      *count = 1;

    status = 0;

  } while (0);

  VoltFileListFree (libCtx, &nameList);
  if (fileHandle != (VoltFileHandle)0)
    fileCtx->CtxCloseFile (fileCtx, &fileHandle);
  if (fileName != (unsigned char *)0)
    Z2Free (fileName);

  if (status == 0)
    return 0;

  VOLT_LOG_ERROR (
    (VtLibCtx)libCtx, status, errorType, fnctLine,
    "VoltGetEntryCountFromIdentity", (char *)0)

  return (status);
}

int VoltGetAuthTokenCountForDistrict (
   VtStorageCtx storageCtx,
   VtDistrictObject reference,
   unsigned int *count,
   unsigned int valueType
   )
{
  int status;
  unsigned int dirNameLen;
  VoltStorageCtx *ctx = (VoltStorageCtx *)storageCtx;
  VoltLibCtx *libCtx = (VoltLibCtx *)(ctx->voltObject.libraryCtx);
  VoltDistrictObject *distObj = (VoltDistrictObject *)reference;
  VtFileNameList *nameList = (VtFileNameList *)0;
  unsigned char *dirName = (unsigned char *)0;
  VOLT_DECLARE_FNCT_LINE (fnctLine)
  VOLT_DECLARE_ERROR_TYPE (errorType)

  /* If this function was called by the VtStorageImplNull 
   * simply return Vt_ERROR_NO_STORAGE_PROVIDER_LOADED
   */
  if (ctx->providerNum == -2)
    return VT_ERROR_NO_STORAGE_PROVIDER_LOADED;

  *count = 0;
  do
  {
    /* If there's no qualified name, this provider can't do anything.
     */
    VOLT_SET_ERROR_TYPE (errorType, VT_ERROR_TYPE_PRIMARY)
    VOLT_SET_FNCT_LINE (fnctLine)
    status = VT_ERROR_INVALID_STORAGE_REF;
    if (distObj->qualDistrictName.data == (unsigned char *)0)
      break;

    /* Get the subdirectory name. Pass NULL, 0 for value to get only
     * the directory name.
     */
    VOLT_SET_ERROR_TYPE (errorType, 0)
    VOLT_SET_FNCT_LINE (fnctLine)
    status = VoltGetFileNameFromValueAlloc (
      ctx, distObj->qualDistrictName.data, distObj->qualDistrictName.len,
      (unsigned char *)0, 0, valueType, &dirName, &dirNameLen);
    if (status != 0)
      break;

    /* Get a list of file names inside the directory. Each file
     * contains one auth token.
     */
    VOLT_SET_FNCT_LINE (fnctLine)
    status = VoltGetFileListAlloc (libCtx, dirName, 0, &nameList);
    if (status != 0)
      break;

    /* All we want to return is the count.
     */
    if (nameList != (VtFileNameList *)0)
      *count = nameList->nameCount;

  } while (0);

  if (dirName != (unsigned char *)0)
    Z2Free (dirName);
  if (nameList != (VtFileNameList *)0)
    VoltFileListFree (libCtx, &nameList);

  if (status == 0)
    return 0;

  VOLT_LOG_ERROR (
    (VtLibCtx)libCtx, status, errorType, fnctLine,
    "VoltGetAuthTokenCountFromDistrict", (char *)0)

  return (status);
}

int VoltDefaultGetIBEPrivateKeyCount (
   VtStorageCtx storageCtx,
   VtIdentityObject reference,
   unsigned int *count
   )
{
  return (VoltGetEntryCountFromIdentity (
    storageCtx, reference, count, VOLT_STORE_DIR_IBE_KEYS,
    VOLT_STORE_DIR_IBE_KEYS_LEN, VOLT_FILE_NAME_VALUE_TYPE_IBE_PRI_KEY));
}

int VoltDefaultGetPrivateSigningKeyCount (
   VtStorageCtx storageCtx,
   VtIdentityObject reference,
   unsigned int *count
   )
{
  return (VoltGetEntryCountFromIdentity (
    storageCtx, reference, count, VOLT_STORE_DIR_SIGN_KEYS,
    VOLT_STORE_DIR_SIGN_KEYS_LEN, VOLT_FILE_NAME_VALUE_TYPE_SIGN_PRI));
}

int VoltDefaultGetPublicSigningCertCount (
   VtStorageCtx storageCtx,
   VtIdentityObject reference,
   unsigned int *count
   )
{
  return (VoltGetEntryCountFromIdentity (
    storageCtx, reference, count, VOLT_STORE_DIR_SIGN_CERTS,
    VOLT_STORE_DIR_SIGN_CERTS_LEN, VOLT_FILE_NAME_VALUE_TYPE_CERT));
}

int VoltDefaultGetAuthTokenCount (
   VtStorageCtx storageCtx,
   VtDistrictObject reference,
   unsigned int *count
   )
{  
  return VoltGetAuthTokenCountForDistrict (
    storageCtx, reference, count, VOLT_FILE_NAME_VALUE_TYPE_IBE_TOKEN);   
}

int VoltRetrieveNewAuthTokensForDistrict (
   VtStorageCtx provider,
   VtDistrictObject reference,
   VoltAuthTokenListObject *tokenListObj,
   unsigned int *newTokenCount,
   unsigned int valueType
   )
{
  int status;
  unsigned int index, dirNameLen, tokenLen, newTokenFlag, tokenCount, count;
  VoltStorageCtx *ctx = (VoltStorageCtx *)provider;
  VoltLibCtx *libCtx = (VoltLibCtx *)(ctx->voltObject.libraryCtx);
  VoltDistrictObject *distObj = (VoltDistrictObject *)reference;
  VtFileNameList *nameList = (VtFileNameList *)0;
  unsigned char *dirName = (unsigned char *)0;
  unsigned char **tokens = (unsigned char **)0;
  VOLT_DECLARE_FNCT_LINE (fnctLine)
  VOLT_DECLARE_ERROR_TYPE (errorType)

  /* If this function was called by the VtStorageImplNull 
   * simply return Vt_ERROR_NO_STORAGE_PROVIDER_LOADED
   */
  if (ctx->providerNum == -2)
    return VT_ERROR_NO_STORAGE_PROVIDER_LOADED;

  count = 0;
  tokenCount = 0;
  do
  {
    /* Make sure the district object contains a qualified name.
     */
    VOLT_SET_ERROR_TYPE (errorType, VT_ERROR_TYPE_PRIMARY)
    VOLT_SET_FNCT_LINE (fnctLine)
    status = VT_ERROR_INVALID_STORAGE_REF;
    if (distObj->qualDistrictName.data == (unsigned char *)0)
      break;

    /* Get the subdirectory name. Pass NULL, 0 for value to get only
     * the directory name.
     */
    VOLT_SET_ERROR_TYPE (errorType, 0)
    VOLT_SET_FNCT_LINE (fnctLine)
    status = VoltGetFileNameFromValueAlloc (
      ctx, distObj->qualDistrictName.data, distObj->qualDistrictName.len,
      (unsigned char *)0, 0, valueType,
      &dirName, &dirNameLen);
    if (status != 0)
      break;

    /* Get a list of file names inside the directory. Each file
     * contains one auth token.
     */
    VOLT_SET_FNCT_LINE (fnctLine)
    status = VoltGetFileListAlloc (libCtx, dirName, 0, &nameList);
    if (status != 0)
      break;

    /* Are there any files? If not, there are no auth tokens.
     */
    if (nameList == (VtFileNameList *)0)
      break;
    if (nameList->nameCount == 0)
      break;

    tokenCount = nameList->nameCount;

    /* Build an arrays for the token pointers.
     */
    VOLT_SET_ERROR_TYPE (errorType, VT_ERROR_TYPE_PRIMARY)
    VOLT_SET_FNCT_LINE (fnctLine)
    status = VT_ERROR_MEMORY;
    count = tokenCount * sizeof (char *);
    tokens = (unsigned char **)Z2Malloc (count, 0);
    if (tokens == (unsigned char **)0)
      break;
    Z2Memset (tokens, 0, count);

    /* Run through all the names, getting the contents of each file.
     */
    VOLT_SET_ERROR_TYPE (errorType, 0) 
    VOLT_SET_FNCT_LINE (fnctLine)
    for (index = 0; index < nameList->nameCount; ++index)
    {
      /* Pass NULL for the directory name, the GetFileListAlloc
       * function already put together the file name with the directory.
       */      
      status = VoltGetFileContentsAlloc (
        ctx, (unsigned char *)0, nameList->nameList[index],
        VOLT_GET_CONTENTS_NULL_TERM, &(tokens[index]), &tokenLen);
      if (status != 0)
        break;
    }
    if (status != 0)
      break;

    /* Add these to the token list object.
     */
    count = 0;
    VOLT_SET_FNCT_LINE (fnctLine)
    for (index = 0; index < nameList->nameCount; ++index)
    {
      status = VoltAddNewAuthToken (
        tokenListObj, tokens[index], &newTokenFlag);
      if (status != 0)
        break;

      /* If the token was added, increment our count of new tokens
       * found.
       */
      if (newTokenFlag != 0)
        count++;
    }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -