メインページ | アルファベット順一覧 | 構成 | ファイル一覧 | 構成メンバ | ファイルメンバ | 関連ページ

# dkcDCF.c

説明を見る。

    00001
    00012 #define DKUTIL_C_DCF_C
    00013 #include "dkcDCF.h"
    00014 #include "dkcGenericFileSystem.h"
    00015 #include "dkcSJISFileSystem.h"
    00016 #include "dkcCryptograph.h"
    00017
    00018 int WINAPI dkcFreeDCF(DKC_DCF **pp){
    00019     DKC_DCF *p = *pp;
    00020     DKC_DCF_FREE_F_TYPE ff;
    00021     if(NULL==pp || NULL==p) return edk_FAILED;
    00022     ff = p->fpFree;
    00023     return ff(pp);
    00024 }
    00025
    00026 int WINAPI dkcFileToDCF(uint32 option,const char *save_filename,const char *target_filename,
    00027                      const void *key,size_t keysize)
    00028 {
    00029     int r = edk_FAILED;
    00030     switch(option){
    00031         case edkcDCF01:
    00032             r = dkcFileToDCF01(save_filename,target_filename,key,keysize);
    00033             break;
    00034     }
    00035     return r;
    00036 }
    00037
    00038 int WINAPI dkcDCFToFile(uint32 option,const char *dest_filename,const char *target_filename,
    00039                      const void *key,size_t keysize)
    00040 {
    00041     int r = edk_FAILED;
    00042     switch(option){
    00043         case edkcDCF01:
    00044             r = dkcDCF01ToFile(dest_filename,target_filename,key,keysize);
    00045             break;
    00046     }
    00047     return r;
    00048 }
    00049
    00050
    00051 BOOL WINAPI dkcDCFPasswordCheck(DKC_DCF *p,const char *filename,const void *password,size_t size)
    00052 {
    00053
    00054     DKC_DCF_INIT_F_TYPE init;
    00055     DKC_DCF_READ_F_TYPE read;
    00056     DKC_DCF_READ_FINAL_F_TYPE readfinal;
    00057     BOOL r = FALSE;
    00058     uint8 tempbuff[1024];
    00059     size_t readsize;
    00060     if(NULL==p) goto Error;
    00061
    00062     init = p->fpInit;
    00063     read = p->fpRead;
    00064     readfinal = p->fpReadFinal;
    00065
    00066     init(p);
    00067     do
    00068     {
    00069         r = read(p,tempbuff,sizeof(tempbuff),&readsize);
    00070
    00071         if(DKUTIL_FAILED(r) && (r != edk_EndProcess))
    00072         {
    00073             goto Error;
    00074         }
    00075
    00076     }while(edk_EndProcess!=r);
    00077
    00078     r = readfinal(p);
    00079     if(DKUTIL_FAILED(r)) goto Error;
    00080
    00081     r = TRUE;
    00082 Error:
    00083     return r;
    00084
    00085 }
    00086
    00087 int WINAPI dkcDCFAllRead(DKC_DCF *p,void *buff,size_t size)
    00088 {
    00089
    00090     DKC_DCF_INIT_F_TYPE init;
    00091     DKC_DCF_READ_F_TYPE read;
    00092     DKC_DCF_READ_FINAL_F_TYPE readfinal;
    00093     size_t readsize;
    00094     uint8 *pBuff = (uint8 *)buff;
    00095     int r = edk_FAILED;
    00096     size_t offset = 0;
    00097
    00098     if(NULL==p) return edk_ArgumentException;
    00099     init = p->fpInit;
    00100     read = p->fpRead;
    00101     readfinal = p->fpReadFinal;
    00102     init(p);
    00103
    00104     do
    00105     {
    00106         r = read(p,pBuff + offset,size - offset,&readsize);
    00107
    00108         if(DKUTIL_FAILED(r) && (r != edk_EndProcess))
    00109         {
    00110             return r;
    00111         }
    00112         offset += readsize;
    00113         if(size < offset){
    00114             return edk_OutputBufferWasLost;
    00115         }else if(size == offset){
    00116             if(edk_EndProcess!=r){
    00117                 return edk_OutputBufferWasLost;
    00118             }
    00119             break;
    00120         }
    00121     }while(edk_EndProcess!=r);
    00122
    00123     r = readfinal(p);
    00124     if(DKUTIL_FAILED(r)) return r;
    00125
    00126     r = edk_SUCCEEDED;
    00127
    00128     return r;
    00129 }
    00130
    00131 int WINAPI dkcDCFFileSizeExpect(const char *filename,uint64 *pv){
    00132     int r;
    00133     DKC_FILE64 *p;
    00134     size_t readsize;
    00135     uint64 tv;
    00136     if(dkcFileExist(filename)==FALSE)
    00137         return edk_FileNotFound;
    00138
    00139     p = dkcAllocFile64(edkcReadMode,filename);
    00140     if(NULL==p) return edk_FAILED;
    00141
    00142     //ファイルの先頭を取得。
    00143     r = dkcFile64Seek(p,SHA512_BIN_BUFFER_SIZE,edkcSeekSet);
    00144     if(DKUTIL_FAILED(r)){goto Error;}
    00145     r = dkcFile64Read(p,pv,sizeof(*pv),&readsize);
    00146     if(DKUTIL_FAILED(r)){goto Error;}
    00147     if(readsize != sizeof(*pv)){
    00148         r = edk_LogicException;
    00149         goto Error;
    00150     }
    00151
    00152     //ファイルの最後までのサイズと比較
    00153     r = dkcFile64Seek(p,0,edkcSeekEnd);
    00154     if(DKUTIL_FAILED(r)){goto Error;}
    00155
    00156     r = dkcFile64Tell(p,&tv);
    00157     if(DKUTIL_FAILED(r)){goto Error;}
    00158
    00159     if(*pv != tv - (SHA512_BIN_BUFFER_SIZE + readsize)){
    00160         r = edk_LogicException;
    00161         goto Error;
    00162     }
    00163     r = edk_SUCCEEDED;
    00164 Error:
    00165     dkcFreeFile64(&p);
    00166     return r;
    00167 }
    00168