#include <str.h>
Inheritance diagram for str:

str objects created by the supplied constructors have null terminators so that they can be used as normal C strings. (For example, they can be passed to strlen().) The terminating null is not considered part of the str object or counted in its length.
For efficiency, the implementation of str uses shared memory and performs garbage collection. Hence the following caveats:
1. A str object returned by a function might not have a null terminator.
2. Do not directly modify a str object via a pointer to its character buffer unless you are sure that no other str objects share that buffer.
3. The amount of memory allocated to a non-empty str object can exceed the size of the string stored in it, but there is no memory allocated when the length is zero.
Call str::purify() to guarantee a null terminator and an unshared character buffer.
Warnings: str::str(const char *p) may truncate binary data copied from p so be very careful in situations like this:
char x[10] = "sdf\0asld\n"; str y = x; // y only gets "sdf\0" and the rest of x is discarded!
Instead, use:
str y(10,x);
or
Also, the concatenation logic does not preserve null terminators. In other words, be careful about:
str a("United "), b("States"); // both null terminated str c = a + b; // a,c possibly not null terminated a.purify(); // a is null terminated again
Recommendations for strict FIPS 140-1 compliance: All applications should use str objects for storing keys as the class's destructor will zeroize the object's memory when it is explicitly destroyed or goes out of scope. If the application does not use the CDK's str class for storing keys, the application must guarantee that the memory used to store keys is zeroized. Class str contains no methods that perform or use cryptographic operations.
Public Types | |
| npos = -1 | |
| = -1 (invalid byte offset or character not found) | |
| enum | { npos = -1 } |
| For compatibility with the standard string class. More... | |
Public Member Functions | |
Constructors and Destructors | |
| str () | |
| Constructor used to create an empty str object. | |
| str (const str &x) | |
| Copy constructor. | |
| str (int len) | |
| Constructor used to create an object of a specified length. | |
| str (int len, const char *p, int max=0) | |
| Constructor used to create an object with specified data. | |
| str (const char *p) | |
| Constructor used to create an object containing an ASCII text string. | |
| ~str () | |
| Destructor, calls clear() to zeroize all data fields. | |
Inspectors and Manipulators | |
| int | length () const |
| Get the length in bytes of this object's data. | |
| char * | constptr () const |
| Get a (const) pointer to the kth byte in this object's internal data buffer. | |
| char * | rawptr (int k=0) const |
| Get a pointer to the kth byte in this object's internal data buffer. | |
| const char * | c_str () |
| Null-terminate this object and get a (const) pointer to its internal data buffer. | |
| void | makeunique () |
| Ensure that this object's character buffer is not shared by another object. | |
| void | nullterminate () |
| Null-terminate this object. | |
| void | purify () |
| Null-terminate this object and ensure that its character buffer is not shared by another str object. | |
| str | skip (int k) const |
| Create a new object containing all but the leftmost k bytes of this object. | |
| str | trunc (int k) const |
| Truncate this str object. | |
| bool | isText () const |
| Predicate used to determine if this object contains printable ASCII text. | |
String Operators | |
| operator const char * () const | |
| Get a pointer to this object's internal data buffer; operator version. | |
| str | operator= (const str &x) |
| Assignment operator used to duplicate a str object. | |
| bool | operator== (const str &y) const |
| Operator used to test equality of two str objects. | |
| bool | operator!= (const str &y) const |
| Operator used to test inequality of two str objects. | |
| int | operator+ () const |
| Operator used to obtain the length in bytes of this object's data. | |
| int | operator[] (int k) const |
| Get the k-th byte in this object's data buffer. | |
| char & | operator[] (int k) |
| Get a reference to the k-th byte in this object's data buffer. | |
| str | operator+ (const str &y) const |
| Create a new str object by concatenating a specified str object onto this one. | |
| void | operator+= (const str &y) |
| Concatenate a specified str object onto this one. | |
| void | operator^= (const str &y) |
| XOR two str object together. | |
Conversion Functions | |
| str | tohex (int withprefix=0) const |
| Convert tbis object's data to a string of ASCII hex digits. | |
| str | tobase64 (int rfcpad=1) const |
| Base64 encode this object. | |
| str | tobin64 () const |
| Base64 decode this object. | |
| double | todouble () const |
| Convert to double. | |
| long | tolong () const |
| Convert to long. | |
| str | towrap (int width) const |
| Line wrap the data in this object. | |
Substrings, Search, and Replace | |
| str | substr (int offset, int length) const |
| Extract a substring from this str object. | |
| int | find (char ch, int offset=0) const |
| Find the first instance of a specified character in this str object. | |
| str | replace (int pos, int n, const str &z) |
| Replace substring with string. | |
| str | insert (int pos, const str &z) |
| Insert substring. | |
| str | erase (int pos, int n) |
| Erase substring. | |
| anonymous enum |
| str | ( | int | len | ) | [inline, explicit] |
Constructor used to create an object of a specified length.
| len | the size of buffer to preallocate in bytes |
| str | ( | int | len, | |
| const char * | p, | |||
| int | max = 0 | |||
| ) | [inline, explicit] |
Constructor used to create an object with specified data.
| len | the length in bytes of the data buffer | |
| p | a pointer to the buffer containing data for the new string | |
| max | the length of this object's data buffer (if more than len bytes is desired) |
| str | ( | const char * | p | ) |
Constructor used to create an object containing an ASCII text string.
| p | a pointer to a null-terminated ASCII text string |
| str erase | ( | int | pos, | |
| int | n | |||
| ) | [inline] |
Erase substring.
| pos | starting offset | |
| n | number of bytes to erase |
| int find | ( | char | ch, | |
| int | offset = 0 | |||
| ) | const |
Find the first instance of a specified character in this str object.
| ch | the character to be found | |
| offset | a starting point for the search |
Insert substring.
| pos | starting offset | |
| z | string to be inserted into this object |
| bool isText | ( | ) | const |
Predicate used to determine if this object contains printable ASCII text.
| int length | ( | ) | const [inline] |
Get the length in bytes of this object's data.
| operator const char * | ( | ) | const [inline] |
Get a pointer to this object's internal data buffer; operator version.
| bool operator!= | ( | const str & | y | ) | const [inline] |
Operator used to test inequality of two str objects.
| y | the str object to which this one is to be compared |
Create a new str object by concatenating a specified str object onto this one.
| y | the str object to be appended to this one |
| int operator+ | ( | ) | const [inline] |
Operator used to obtain the length in bytes of this object's data.
Assignment operator used to duplicate a str object.
| x | the str object to assign to this object |
Reimplemented in asn.
| bool operator== | ( | const str & | y | ) | const |
Operator used to test equality of two str objects.
| y | the str object to which this one is to be compared |
| char& operator[] | ( | int | k | ) | [inline] |
Get a reference to the k-th byte in this object's data buffer.
| k | the index of the byte to be dereferenced |
Use of Use of this member function is dangerous. Remember that a str object's internal data buffer may be shared by other str objects.
| int operator[] | ( | int | k | ) | const [inline] |
Get the k-th byte in this object's data buffer.
| k | the index of the byte to return |
| void operator^= | ( | const str & | y | ) |
XOR two str object together.
| y | the str to be XOR'ed into this one |
| char* rawptr | ( | int | k = 0 |
) | const [inline] |
Get a pointer to the kth byte in this object's internal data buffer.
| k | a starting offset into this object's data buffer |
Replace substring with string.
| pos | starting offset | |
| n | number of characters to replace | |
| z | replacement string |
| str skip | ( | int | k | ) | const |
Create a new object containing all but the leftmost k bytes of this object.
| k | the number of bytes to be skipped |
| str substr | ( | int | offset, | |
| int | length | |||
| ) | const |
Extract a substring from this str object.
| offset | the starting index of the substring | |
| length | the length of the substring to be extracted |
| str tobase64 | ( | int | rfcpad = 1 |
) | const |
Base64 encode this object.
| rfcpad | padding indicator: use 1 to ensure that the encoded length is a multiple of 4, 0 if you don't care |
| str tobin64 | ( | ) | const |
Base64 decode this object.
| double todouble | ( | ) | const [inline] |
Convert to double.
| str tohex | ( | int | withprefix = 0 |
) | const |
Convert tbis object's data to a string of ASCII hex digits.
| withprefix | prefix indicator: 1 to prepend '0x' to the output string, 0 to omit this prefix |
| long tolong | ( | ) | const |
Convert to long.
| str towrap | ( | int | width | ) | const |
Line wrap the data in this object.
| width | the desired line length |
| str trunc | ( | int | k | ) | const |
Truncate this str object.
| k | the number of bytes to retain |
| ISC Cryptographic Development Kit - User's Guide | |
| Questions? E-mail ISC technical support | |
| Copyright© 2002-2006 Information Security Corp. All rights reserved. |