QCAD
Open Source 2D CAD
Loading...
Searching...
No Matches
opennurbs_base64.h
Go to the documentation of this file.
1/* $NoKeywords: $ */
2/*
3//
4// Copyright (c) 1993-2007 Robert McNeel & Associates. All rights reserved.
5// Rhinoceros is a registered trademark of Robert McNeel & Assoicates.
6//
7// THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY.
8// ALL IMPLIED WARRANTIES OF FITNESS FOR ANY PARTICULAR PURPOSE AND OF
9// MERCHANTABILITY ARE HEREBY DISCLAIMED.
10//
11// For complete openNURBS copyright information see <http://www.opennurbs.org>.
12//
14*/
15
16#if !defined(OPENNURBS_BASE64_INC_)
17#define OPENNURBS_BASE64_INC_
18
20
22{
23public:
25 virtual ~ON_EncodeBase64();
26
27 void Begin();
28
29 // Calling Encode will generate at least
30 // sizeof_buffer/57 and at most (sizeof_buffer+56)/57
31 // calls to Output(). Every callback to Output() will
32 // have m_output_count = 76.
33 void Encode(const void* buffer, size_t sizeof_buffer);
34
35 // Calling End may generate a single call to Output()
36 // If it does generate a single call to Output(),
37 // then m_output_count will be between 1 and 76.
38 void End(); // may generate a single call to Output().
39
40 // With a single exception, when Output() is called,
41 // 57 input bytes have been encoded into 76 output
42 // characters with ASCII codes A-Z, a-z, 0-9, +, /.
43 // m_output_count will be 76
44 // m_output[0...(m_output_count-1)] will be the base 64
45 // encoding.
46 // m_output[m_output_count] = 0.
47 // The Output() function can modify the values of m_output[]
48 // and m_output_count anyway it wants.
49 virtual void Output();
50
51 // Total number of bytes passed to Encode().
53
54 // When the virtual Output() is called, there are m_output_count (1 to 76)
55 // characters of base64 encoded output in m_output[]. The remainder of
56 // the m_output[] array is zero. The Output function may modify the
57 // contents of m_output[] any way it sees fit.
59 char m_output[80];
60
61private:
62 // input waiting to be encoded
63 // At most 56 bytes can be waiting to be processed in m_input[].
64 unsigned int m_unused2; // Here for alignment purposes. Never used by opennurbs.
65 unsigned int m_input_count;
66 unsigned char m_input[64];
67
68 void EncodeHelper1(const unsigned char*, char*);
69 void EncodeHelper2(const unsigned char*, char*);
70 void EncodeHelper3(const unsigned char*, char*);
71 void EncodeHelper57(const unsigned char*);
72};
73
75
77{
78public:
80 virtual ~ON_DecodeBase64();
81
82 void Begin();
83
84 // Decode will generate zero or more callbacks to the
85 // virtual Output() function. If the base 64 encoded information
86 // is in pieces, you can call Decode() for each piece. For example,
87 // if your encoded information is in a text file, you might call
88 // Decode() for every line in the file. Decode() returns 0 if
89 // there is nothing in base64str to decode or if it detects an
90 // error that prevents any further decoding. The function Error()
91 // can be used to determine if an error occured. Otherwise,
92 // Decode() returns a pointer to the location in the string where
93 // it stopped decoding because it detected a character, like a null
94 // terminator, an end of line character, or any other character
95 // that could not be part of the base 64 encoded information.
96 const char* Decode(const char* base64str);
97 const char* Decode(const char* base64str, size_t base64str_count);
98 const wchar_t* Decode(const wchar_t* base64str);
99 const wchar_t* Decode(const wchar_t* base64str, size_t base64str_count);
100
101 // You must call End() when Decode() returns 0 or when you have
102 // reached the end of your encoded information. End() may
103 // callback to Output() zero or one time. If all the information
104 // passed to Decode() was successfully decoded, then End()
105 // returns true. If something was not decoded, then End()
106 // returns false.
107 bool End();
108
109 // Override the virtual Output() callback function to process the
110 // decoded output. Each time Output() is called there are m_output_count
111 // bytes in the m_output[] array.
112 // Every call to Decode() can result in zero, one, or many callbacks
113 // to Output(). Calling End() may result in zero or one callbacks
114 // to Output().
115 virtual void Output();
116
117 // m_decode_count = total number of input base64 characters
118 // that Decode() has decoded.
119 unsigned int m_decode_count;
120
121 int m_output_count; // 0 to 512
122 unsigned char m_output[512];
123
124 // Call if your Output() function detects an error and
125 // wants to stop further decoding.
126 void SetError();
127
128 // Returns true if an error occured during decoding because
129 // invalid input was passed to Decode().
130 const bool Error() const;
131
132private:
133 int m_status; // 1: error - decoding stopped
134 // 2: '=' encountered as 3rd char in Decode()
135 // 3: successfully parsed "**=="
136 // 4: successfully parsed "***="
137 // 5: End() successfully called.
138
139 // cached encoded input from previous call to Decode()
141 int m_cache[4];
142
143 void DecodeHelper1(); // decodes "**==" quartet into 1 byte
144 void DecodeHelper2(); // decodes "***=" quartet into 2 bytes
145};
146
147#endif
Definition Error.h:34
Definition opennurbs_base64.h:77
int m_status
Definition opennurbs_base64.h:133
int m_output_count
Definition opennurbs_base64.h:121
int m_cache_count
Definition opennurbs_base64.h:140
unsigned int m_decode_count
Definition opennurbs_base64.h:119
Definition opennurbs_base64.h:22
int m_encode_count
Definition opennurbs_base64.h:52
int m_output_count
Definition opennurbs_base64.h:58
unsigned int m_unused2
Definition opennurbs_base64.h:64
unsigned int m_input_count
Definition opennurbs_base64.h:65
#define ON_CLASS
Definition opennurbs_defines.h:91