\doxysection{eet-\/data-\/cipher\+\_\+decipher.\+c}
\hypertarget{eet-data-cipher_decipher_8c-example}{}\label{eet-data-cipher_decipher_8c-example}
\begin{DoxyCodeInclude}{0}
\DoxyCodeLine{\textcolor{comment}{//Compile\ with:}}
\DoxyCodeLine{\textcolor{comment}{//\ gcc\ -\/o\ eet-\/data-\/cipher\_decipher\ eet-\/data-\/cipher\_decipher.c\ \`{}pkg-\/config\ -\/-\/cflags\ -\/-\/libs\ eet\ eina`}}
\DoxyCodeLine{}
\DoxyCodeLine{\textcolor{preprocessor}{\#include\ <\mbox{\hyperlink{Eina_8h}{Eina.h}}>}}
\DoxyCodeLine{\textcolor{preprocessor}{\#include\ <\mbox{\hyperlink{Eet_8h}{Eet.h}}>}}
\DoxyCodeLine{\textcolor{preprocessor}{\#include\ <stdio.h>}}
\DoxyCodeLine{\textcolor{preprocessor}{\#include\ <limits.h>}}
\DoxyCodeLine{\textcolor{preprocessor}{\#include\ <sys/types.h>}}
\DoxyCodeLine{\textcolor{preprocessor}{\#include\ <sys/stat.h>}}
\DoxyCodeLine{\textcolor{preprocessor}{\#include\ <unistd.h>}}
\DoxyCodeLine{\textcolor{preprocessor}{\#include\ <string.h>}}
\DoxyCodeLine{}
\DoxyCodeLine{\textcolor{keywordtype}{int}}
\DoxyCodeLine{main(\textcolor{keywordtype}{void})}
\DoxyCodeLine{\{}
\DoxyCodeLine{\ \ \ \textcolor{keyword}{const}\ \textcolor{keywordtype}{char}\ *buffer\ =\ \textcolor{stringliteral}{"{}Here\ is\ a\ string\ of\ data\ to\ save\ !"{}};}
\DoxyCodeLine{\ \ \ \textcolor{keyword}{const}\ \textcolor{keywordtype}{char}\ *key\ =\ \textcolor{stringliteral}{"{}This\ is\ a\ crypto\ key"{}};}
\DoxyCodeLine{\ \ \ \textcolor{keyword}{const}\ \textcolor{keywordtype}{char}\ *key\_bad\ =\ \textcolor{stringliteral}{"{}This\ is\ another\ crypto\ key"{}};}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Eet__File__Group_ga8d9779184a9870c1a225f1f40c76e8a7}{Eet\_File}}\ *ef;}
\DoxyCodeLine{\ \ \ \textcolor{keywordtype}{char}\ *test;}
\DoxyCodeLine{\ \ \ \textcolor{keywordtype}{int}\ size;}
\DoxyCodeLine{\ \ \ \textcolor{keywordtype}{int}\ tmpfd;}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Eina__Stringshare__Group_gae8d53f367d5da5acfd19af6c235831d5}{Eina\_Tmpstr}}\ *tmpf\ =\ NULL;}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Eet__Group_ga9903687bfa20fe9a9e59d4c1d213e89a}{eet\_init}}();}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \textcolor{keywordflow}{if}\ (-\/1\ ==\ (tmpfd\ =\ \mbox{\hyperlink{group__Eina__File__Group_gac77efa39c12ba6880a5bbdca004080fb}{eina\_file\_mkstemp}}(\textcolor{stringliteral}{"{}eet\_cipher\_example\_XXXXXX"{}},\ \&tmpf))\ ||\ !!close(tmpfd))}
\DoxyCodeLine{\ \ \ \ \ \{}
\DoxyCodeLine{\ \ \ \ \ \ \ \ fprintf(}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ stderr,\ \textcolor{stringliteral}{"{}ERROR:\ could\ not\ create\ temporary\ file\ (\%s)\ :\ \%s\(\backslash\)n"{}},}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ tmpf,\ strerror(errno));}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \textcolor{keywordflow}{goto}\ panic;}
\DoxyCodeLine{\ \ \ \ \ \}}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \textcolor{comment}{/*\ Crypt\ an\ eet\ file.\ */}}
\DoxyCodeLine{\ \ \ ef\ =\ \mbox{\hyperlink{group__Eet__File__Group_ga675160a758832ee812edf7f64ed30ee6}{eet\_open}}(tmpf,\ \mbox{\hyperlink{group__Eet__File__Group_ggaa8e1a7af50fefaf15eb2f69543d24998a8f395f56fba48be007c65be51d799ee9}{EET\_FILE\_MODE\_WRITE}});}
\DoxyCodeLine{\ \ \ \textcolor{keywordflow}{if}\ (!ef)}
\DoxyCodeLine{\ \ \ \ \ \{}
\DoxyCodeLine{\ \ \ \ \ \ \ \ fprintf(}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ stderr,\ \textcolor{stringliteral}{"{}ERROR:\ could\ not\ access\ file\ (\%s).\(\backslash\)n"{}},\ tmpf);}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \textcolor{keywordflow}{goto}\ error;}
\DoxyCodeLine{\ \ \ \ \ \}}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \textcolor{keywordflow}{if}\ (!\mbox{\hyperlink{group__Eet__File__Cipher__Group_ga0c08a5881d6fd3474a8cbe03a445aff3}{eet\_write\_cipher}}(ef,\ \textcolor{stringliteral}{"{}keys/tests"{}},\ buffer,\ strlen(buffer)\ +\ 1,\ 0,\ key))}
\DoxyCodeLine{\ \ \ \ \ \{}
\DoxyCodeLine{\ \ \ \ \ \ \ \ fprintf(}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ stderr,\ \textcolor{stringliteral}{"{}ERROR:\ could\ not\ access\ file\ (\%s).\(\backslash\)n"{}},\ tmpf);}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \textcolor{keywordflow}{goto}\ error;}
\DoxyCodeLine{\ \ \ \ \ \}}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Eet__File__Group_ga1675fef1f6012c1e02ae313d13dc3e03}{eet\_close}}(ef);}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \textcolor{comment}{/*\ Decrypt\ an\ eet\ file.\ */}}
\DoxyCodeLine{\ \ \ ef\ =\ \mbox{\hyperlink{group__Eet__File__Group_ga675160a758832ee812edf7f64ed30ee6}{eet\_open}}(tmpf,\ \mbox{\hyperlink{group__Eet__File__Group_ggaa8e1a7af50fefaf15eb2f69543d24998a416f7e9a76b8131a44bbeedb13060c81}{EET\_FILE\_MODE\_READ}});}
\DoxyCodeLine{\ \ \ \textcolor{keywordflow}{if}\ (!ef)}
\DoxyCodeLine{\ \ \ \ \ \{}
\DoxyCodeLine{\ \ \ \ \ \ \ \ fprintf(}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ stderr,\ \textcolor{stringliteral}{"{}ERROR:\ could\ not\ access\ file\ (\%s).\(\backslash\)n"{}},\ tmpf);}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \textcolor{keywordflow}{goto}\ error;}
\DoxyCodeLine{\ \ \ \ \ \}}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ test\ =\ \mbox{\hyperlink{group__Eet__File__Cipher__Group_gac6d14b588c7e192dc621f466749f3177}{eet\_read\_cipher}}(ef,\ \textcolor{stringliteral}{"{}keys/tests"{}},\ \&size,\ key);}
\DoxyCodeLine{\ \ \ \textcolor{keywordflow}{if}\ (!test)}
\DoxyCodeLine{\ \ \ \ \ \{}
\DoxyCodeLine{\ \ \ \ \ \ \ \ fprintf(}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ stderr,\ \textcolor{stringliteral}{"{}ERROR:\ could\ decript\ contents\ on\ file\ \%s,\ with\ key\ \%s.\(\backslash\)n"{}},}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ tmpf,\ key);}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \textcolor{keywordflow}{goto}\ error;}
\DoxyCodeLine{\ \ \ \ \ \}}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \textcolor{keywordflow}{if}\ (size\ !=\ (\textcolor{keywordtype}{int})strlen(buffer)\ +\ 1)}
\DoxyCodeLine{\ \ \ \ \ \{}
\DoxyCodeLine{\ \ \ \ \ \ \ \ fprintf(}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ stderr,\ \textcolor{stringliteral}{"{}ERROR:\ something\ is\ wrong\ with\ the\ decripted\ data\(\backslash\)n"{}});}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \textcolor{keywordflow}{goto}\ error;}
\DoxyCodeLine{\ \ \ \ \ \}}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \textcolor{keywordflow}{if}\ (memcmp(test,\ buffer,\ strlen(buffer)\ +\ 1)\ !=\ 0)}
\DoxyCodeLine{\ \ \ \ \ \{}
\DoxyCodeLine{\ \ \ \ \ \ \ \ fprintf(}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ stderr,\ \textcolor{stringliteral}{"{}ERROR:\ something\ is\ wrong\ with\ the\ decripted\ data\(\backslash\)n"{}});}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \textcolor{keywordflow}{goto}\ error;}
\DoxyCodeLine{\ \ \ \ \ \}}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Eet__File__Group_ga1675fef1f6012c1e02ae313d13dc3e03}{eet\_close}}(ef);}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \textcolor{comment}{/*\ Decrypt\ an\ eet\ file,\ now\ using\ our\ BAD\ key!!\ */}}
\DoxyCodeLine{\ \ \ ef\ =\ \mbox{\hyperlink{group__Eet__File__Group_ga675160a758832ee812edf7f64ed30ee6}{eet\_open}}(tmpf,\ \mbox{\hyperlink{group__Eet__File__Group_ggaa8e1a7af50fefaf15eb2f69543d24998a416f7e9a76b8131a44bbeedb13060c81}{EET\_FILE\_MODE\_READ}});}
\DoxyCodeLine{\ \ \ \textcolor{keywordflow}{if}\ (!ef)}
\DoxyCodeLine{\ \ \ \ \ \{}
\DoxyCodeLine{\ \ \ \ \ \ \ \ fprintf(}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ stderr,\ \textcolor{stringliteral}{"{}ERROR:\ could\ not\ access\ file\ (\%s).\(\backslash\)n"{}},\ tmpf);}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \textcolor{keywordflow}{goto}\ error;}
\DoxyCodeLine{\ \ \ \ \ \}}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ test\ =\ \mbox{\hyperlink{group__Eet__File__Cipher__Group_gac6d14b588c7e192dc621f466749f3177}{eet\_read\_cipher}}(ef,\ \textcolor{stringliteral}{"{}keys/tests"{}},\ \&size,\ key\_bad);}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \textcolor{keywordflow}{if}\ (size\ ==\ (\textcolor{keywordtype}{int})strlen(buffer)\ +\ 1)}
\DoxyCodeLine{\ \ \ \ \ \textcolor{keywordflow}{if}\ (memcmp(test,\ buffer,\ strlen(buffer)\ +\ 1)\ ==\ 0)}
\DoxyCodeLine{\ \ \ \ \ \ \ \{}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ fprintf(}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ stderr,\ \textcolor{stringliteral}{"{}ERROR:\ something\ is\ wrong\ with\ the\ contents\ of\ \%s,\ as"{}}}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{stringliteral}{"{}\ we\ accessed\ it\ with\ a\ different\ key\ and\ it\ decripted\ our"{}}}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{stringliteral}{"{}\ information\ right.\(\backslash\)n"{}},\ tmpf);}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{goto}\ error;}
\DoxyCodeLine{\ \ \ \ \ \ \ \}}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Eet__File__Group_ga1675fef1f6012c1e02ae313d13dc3e03}{eet\_close}}(ef);}
\DoxyCodeLine{}
\DoxyCodeLine{error:}
\DoxyCodeLine{\ \ \ \textcolor{keywordflow}{if}\ (unlink(tmpf)\ !=\ 0)}
\DoxyCodeLine{\ \ \ \ \ \{}
\DoxyCodeLine{\ \ \ \ \ \ \ \ fprintf(}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ stderr,\ \textcolor{stringliteral}{"{}ERROR:\ could\ not\ unlink\ file\ (\%s)\%d.\(\backslash\)n"{}},\ tmpf,\ errno);}
\DoxyCodeLine{\ \ \ \ \ \}}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Eina__Stringshare__Group_ga0c32cf7aadbc1fcd60500d5bb9c03c93}{eina\_tmpstr\_del}}(tmpf);}
\DoxyCodeLine{}
\DoxyCodeLine{panic:}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Eet__Group_gacbc7583179399d3b3e7b003e911f866f}{eet\_shutdown}}();}
\DoxyCodeLine{\}}
\DoxyCodeLine{}

\end{DoxyCodeInclude}
 