]>
git.saurik.com Git - apple/security.git/blob - cdsa/cdsa_utilities/digestobject.h
2 * Copyright (c) 2000-2001 Apple Computer, Inc. All Rights Reserved.
4 * The contents of this file constitute Original Code as defined in and are
5 * subject to the Apple Public Source License Version 1.2 (the 'License').
6 * You may not use this file except in compliance with the License. Please obtain
7 * a copy of the License at http://www.apple.com/publicsource and read it before
10 * This Original Code and all software distributed under the License are
11 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS
12 * OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, INCLUDING WITHOUT
13 * LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14 * PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. Please see the License for the
15 * specific language governing rights and limitations under the License.
20 * digestobject.h - generic virtual Digest base class
23 #ifndef _DIGEST_OBJECT_H_
24 #define _DIGEST_OBJECT_H_
26 #include <CoreServices/../Frameworks/CarbonCore.framework/Headers/MacTypes.h>
27 #include <Security/cssmalloc.h>
29 /* common virtual digest class */
32 DigestObject() : mInitFlag(false), mIsDone(false) { }
33 virtual ~DigestObject() { }
36 * The remaining functions must be implemented by subclass.
38 /* init is reusable */
39 virtual void digestInit() = 0;
42 virtual void digestUpdate(
46 /* obtain digest (once only per init, update, ... cycle) */
47 virtual void digestFinal(
48 void *digest
) = 0; /* RETURNED, alloc'd by caller */
50 /* sublass-specific copy */
51 virtual DigestObject
*digestClone() const = 0;
53 virtual size_t digestSizeInBytes() const = 0;
59 bool initFlag() { return mInitFlag
; }
60 void setInitFlag(bool flag
) { mInitFlag
= flag
; }
61 bool isDone() { return mIsDone
; }
62 void setIsDone(bool done
) { mIsDone
= done
; }
66 * NullDigest.h - nop digest for use with raw signature algorithms.
67 * NullDigest(someData) = someData.
69 class NullDigest
: public DigestObject
72 NullDigest() : mInBuf(NULL
), mInBufSize(0)
78 /* reusable - reset */
80 assert(mInBuf
!= NULL
);
81 memset(mInBuf
, 0, mInBufSize
);
82 CssmAllocator::standard().free(mInBuf
);
97 mInBuf
= CssmAllocator::standard().realloc(mInBuf
, mInBufSize
+ len
);
98 memmove((uint8
*)mInBuf
+ mInBufSize
, data
, len
);
102 virtual void digestFinal(
105 memmove(digest
, mInBuf
, mInBufSize
);
108 virtual DigestObject
*digestClone() const
110 NullDigest
*cloned
= new NullDigest
;
111 cloned
->digestUpdate(mInBuf
, mInBufSize
);
115 /* unique to NullDigest - just obtain current data ptr, no copy */
116 virtual const void *digestPtr() { return mInBuf
; }
118 size_t digestSizeInBytes() const
128 #endif /* _DIGEST_OBJECT_H_ */