]>
git.saurik.com Git - apple/security.git/blob - libsecurity_cdsa_utilities/lib/digestobject.h
2 * Copyright (c) 2000-2004,2006 Apple Computer, Inc. All Rights Reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
21 * @APPLE_LICENSE_HEADER_END@
26 * digestobject.h - generic virtual Digest base class
29 #ifndef _DIGEST_OBJECT_H_
30 #define _DIGEST_OBJECT_H_
32 #include <CoreServices/../Frameworks/CarbonCore.framework/Headers/MacTypes.h>
33 #include <security_cdsa_utilities/cssmalloc.h>
35 /* common virtual digest class */
38 DigestObject() : mInitFlag(false), mIsDone(false) { }
39 virtual ~DigestObject() { }
42 * The remaining functions must be implemented by subclass.
44 /* init is reusable */
45 virtual void digestInit() = 0;
48 virtual void digestUpdate(
52 /* obtain digest (once only per init, update, ... cycle) */
53 virtual void digestFinal(
54 void *digest
) = 0; /* RETURNED, alloc'd by caller */
56 /* sublass-specific copy */
57 virtual DigestObject
*digestClone() const = 0;
59 virtual size_t digestSizeInBytes() const = 0;
65 bool initFlag() { return mInitFlag
; }
66 void setInitFlag(bool flag
) { mInitFlag
= flag
; }
67 bool isDone() { return mIsDone
; }
68 void setIsDone(bool done
) { mIsDone
= done
; }
72 * NullDigest.h - nop digest for use with raw signature algorithms.
73 * NullDigest(someData) = someData.
75 class NullDigest
: public DigestObject
78 NullDigest() : mInBuf(NULL
), mInBufSize(0)
84 /* reusable - reset */
86 assert(mInBuf
!= NULL
);
87 memset(mInBuf
, 0, mInBufSize
);
88 Allocator::standard().free(mInBuf
);
103 mInBuf
= Allocator::standard().realloc(mInBuf
, mInBufSize
+ len
);
104 memmove((uint8
*)mInBuf
+ mInBufSize
, data
, len
);
108 virtual void digestFinal(
111 memmove(digest
, mInBuf
, mInBufSize
);
114 virtual DigestObject
*digestClone() const
116 NullDigest
*cloned
= new NullDigest
;
117 cloned
->digestUpdate(mInBuf
, mInBufSize
);
121 /* unique to NullDigest - just obtain current data ptr, no copy */
122 virtual const void *digestPtr() { return mInBuf
; }
124 size_t digestSizeInBytes() const
134 #endif /* _DIGEST_OBJECT_H_ */