]>
git.saurik.com Git - apple/security.git/blob - SecuritySNACCRuntime/c++-lib/inc/asn-buf.h
a9c2f1d1e430d97d2b610f72f9e00ad9df6832bc
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.
19 // file: .../c++-lib/inc/asn-buf.h - buffer class
22 // Copyright (C) 1992 Michael Sample and the University of British Columbia
24 // This library is free software; you can redistribute it and/or
25 // modify it provided that this copyright/license information is retained
28 // If you modify this file, you must clearly indicate your changes.
30 // This source code is distributed in the hope that it will be
31 // useful, but WITHOUT ANY WARRANTY; without even the implied warranty
32 // of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
34 // $Header: /cvs/Darwin/Security/SecuritySNACCRuntime/c++-lib/inc/asn-buf.h,v 1.1.1.1 2001/05/18 23:14:06 mb Exp $
35 // $Log: asn-buf.h,v $
36 // Revision 1.1.1.1 2001/05/18 23:14:06 mb
37 // Move from private repository to open source repository
39 // Revision 1.3 2001/05/05 00:59:17 rmurphy
40 // Adding darwin license headers
42 // Revision 1.2 2000/06/15 18:48:23 dmitch
43 // Snacc-generated source files, now part of CVS tree to allow for cross-platform build of snaccRuntime.
45 // Revision 1.1.1.1 2000/03/09 01:00:05 rmurphy
46 // Base Fortissimo Tree
48 // Revision 1.4 1999/08/06 16:13:18 mb
49 // Set readError when doing a GetSeg past the end of the buffer. This fixes many potential bugs and hangs when doing streaming decodes with embedded data.
51 // Revision 1.3 1999/07/14 23:53:55 aram
52 // Made const correct so things build with CW 5.0
54 // Revision 1.2 1999/03/04 00:43:20 mb
55 // Made buffer full check work for NULL buffer in an unsigned int context
57 // Revision 1.1 1999/02/25 05:21:41 mb
58 // Added snacc c++ library
60 // Revision 1.5 1997/02/16 20:25:35 rj
61 // check-in of a few cosmetic changes
63 // Revision 1.4 1995/07/25 20:18:58 rj
64 // changed `_' to `-' in file names.
66 // Revision 1.3 1994/10/08 04:15:38 rj
67 // fixed both Copy()'s name and implementation to CopyOut() that always returns the number of bytes copied out instead of 0 in case less than the requested amount is available.
69 // several `unsigned long int' turned into `size_t'.
71 // Revision 1.2 1994/08/28 10:00:46 rj
72 // comment leader fixed.
74 // Revision 1.1 1994/08/28 09:20:28 rj
75 // first check-in. for a list of changes to the snacc-1.1 distribution please refer to the ChangeLog.
92 // install data for reading or blank blk for writing in buffer
93 // must be followed by 'mode' setting method call
94 void Init ( char * data
, size_t dataLen
)
96 readError
= writeError
= 1 ;
98 blkEnd
= data
+ dataLen
;
99 dataStart
= dataEnd
= readLoc
= blkEnd
;
102 void ResetInReadMode ()
109 void ResetInWriteRvsMode ()
111 dataStart
= dataEnd
= blkEnd
;
116 void InstallData ( const char * data
, size_t dataLen
)
118 Init ( const_cast < char *>( data
), dataLen
);
119 dataStart
= blkStart
;
123 size_t DataLen () { return dataEnd
- dataStart
; }
124 char * DataPtr () { return dataStart
; }
125 size_t BlkLen () { return blkEnd
- blkStart
; }
126 char * BlkPtr () { return blkStart
; }
127 bool Eod () { return readLoc
>= dataEnd
; }
128 bool ReadError () { return readError
; }
129 bool WriteError () { return writeError
; }
131 void Skip ( size_t skipLen
)
133 if (( readLoc
+ skipLen
) > dataEnd
)
142 size_t CopyOut ( char * dst
, size_t copyLen
)
144 if ( readLoc
+ copyLen
> dataEnd
)
146 copyLen
= dataEnd
- readLoc
;
149 memcpy ( dst
, readLoc
, copyLen
);
154 unsigned char PeekByte ()
165 char * GetSeg ( size_t * lenPtr
)
167 char * retVal
= readLoc
;
168 if (( readLoc
+ * lenPtr
) > dataEnd
)
170 * lenPtr
= dataEnd
- readLoc
;
173 /* Attempting to read more bytes than left in the buffer is a read error --Michael. */
185 void PutSegRvs ( char * seg
, size_t segLen
)
187 if ( dataStart
< ( blkStart
+ segLen
))
192 memcpy ( dataStart
, seg
, segLen
);
196 unsigned char GetByte ()
207 void PutByteRvs ( unsigned char byte
)
209 if ( dataStart
<= blkStart
)
212 *(-- dataStart
) = byte
;
216 #endif /* conditional include */