magick.c

Go to the documentation of this file.
00001 /*
00002 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00003 %                                                                             %
00004 %                                                                             %
00005 %                                                                             %
00006 %                  M   M   AAA    GGGG  IIIII   CCCC  K   K                   %
00007 %                  MM MM  A   A  G        I    C      K  K                    %
00008 %                  M M M  AAAAA  G GGG    I    C      KKK                     %
00009 %                  M   M  A   A  G   G    I    C      K  K                    %
00010 %                  M   M  A   A   GGGG  IIIII   CCCC  K   K                   %
00011 %                                                                             %
00012 %                         Wizard's Toolkit Magick Methods                     %
00013 %                                                                             %
00014 %                             Software Design                                 %
00015 %                               John Cristy                                   %
00016 %                               March 2003                                    %
00017 %                                                                             %
00018 %                                                                             %
00019 %  Copyright 1999-2010 ImageMagick Studio LLC, a non-profit organization      %
00020 %  dedicated to making software imaging solutions freely available.           %
00021 %                                                                             %
00022 %  You may not use this file except in compliance with the License.  You may  %
00023 %  obtain a copy of the License at                                            %
00024 %                                                                             %
00025 %    http://www.wizards-toolkit.org/script/license.php                        %
00026 %                                                                             %
00027 %  Unless required by applicable law or agreed to in writing, software        %
00028 %  distributed under the License is distributed on an "AS IS" BASIS,          %
00029 %  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.   %
00030 %  See the License for the specific language governing permissions and        %
00031 %  limitations under the License.                                             %
00032 %                                                                             %
00033 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00034 %
00035 %
00036 */
00037 
00038 /*
00039   Include declarations.
00040 */
00041 #include "wizard/studio.h"
00042 #include "wizard/hash.h"
00043 #include "wizard/magick.h"
00044 #include "wizard/string_.h"
00045 /*
00046   Global declaractions.
00047 */
00048 unsigned char
00049   MagickWizard[4] =
00050   {
00051     (unsigned char) 0x45,
00052                 (unsigned char) 0x45,
00053     (unsigned char) 0x53,
00054     (unsigned char) 0x7f
00055   },  /* EES\177 */
00056   WizardMagick[4] =
00057         {
00058           (unsigned char) 0x7f,
00059                 (unsigned char) 0x53,
00060                 (unsigned char) 0x45,
00061                 (unsigned char) 0x45
00062   };  /* \177SEE */
00063 
00064 /*
00065 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00066 %                                                                             %
00067 %                                                                             %
00068 %                                                                             %
00069 %   G e t W i z a r d M a g i c k                                             %
00070 %                                                                             %
00071 %                                                                             %
00072 %                                                                             %
00073 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00074 %
00075 %  GetWizardMagick() produces a unique signature useful for verifying that a
00076 %  structure or file is in fact Wizard related.
00077 %
00078 %  The format of the GetWizardMagick method is:
00079 %
00080 %      StringInfo GetWizardMagick(const char *signature,const size_t length)
00081 %
00082 %  A description of each parameter follows:
00083 %
00084 %    o signature: Derive the magick from this signature.
00085 %
00086 %
00087 */
00088 WizardExport StringInfo *GetWizardMagick(const unsigned char *signature,
00089   const size_t length)
00090 {
00091   HashInfo
00092     *hash_info;
00093 
00094   StringInfo
00095     *magick,
00096     *tag;
00097 
00098   hash_info=AcquireHashInfo(SHA256Hash);
00099   InitializeHash(hash_info);
00100   tag=AcquireStringInfo(length);
00101   SetStringInfoDatum(tag,signature);
00102   UpdateHash(hash_info,tag);
00103   tag=DestroyStringInfo(tag);
00104   FinalizeHash(hash_info);
00105   magick=CloneStringInfo(GetHashDigest(hash_info));
00106   hash_info=DestroyHashInfo(hash_info);
00107   return(magick);
00108 }
Generated by  doxygen 1.6.2-20100208