commit | author | age
|
6e1425
|
1 |
// |
H |
2 |
// GTMBase64.h |
|
3 |
// |
|
4 |
// Copyright 2006-2008 Google Inc. |
|
5 |
// |
|
6 |
// Licensed under the Apache License, Version 2.0 (the "License"); you may not |
|
7 |
// use this file except in compliance with the License. You may obtain a copy |
|
8 |
// of the License at |
|
9 |
// |
|
10 |
// http://www.apache.org/licenses/LICENSE-2.0 |
|
11 |
// |
|
12 |
// Unless required by applicable law or agreed to in writing, software |
|
13 |
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
|
14 |
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
|
15 |
// License for the specific language governing permissions and limitations under |
|
16 |
// the License. |
|
17 |
// |
|
18 |
|
|
19 |
#import <Foundation/Foundation.h> |
|
20 |
#import "GTMDefines.h" |
|
21 |
|
|
22 |
// GTMBase64 |
|
23 |
// |
|
24 |
/// Helper for handling Base64 and WebSafeBase64 encodings |
|
25 |
// |
|
26 |
/// The webSafe methods use different character set and also the results aren't |
|
27 |
/// always padded to a multiple of 4 characters. This is done so the resulting |
|
28 |
/// data can be used in urls and url query arguments without needing any |
|
29 |
/// encoding. You must use the webSafe* methods together, the data does not |
|
30 |
/// interop with the RFC methods. |
|
31 |
// |
|
32 |
@interface WASdkGTMBase64 : NSObject |
|
33 |
|
|
34 |
// |
|
35 |
// Standard Base64 (RFC) handling |
|
36 |
// |
|
37 |
|
|
38 |
// encodeData: |
|
39 |
// |
|
40 |
/// Base64 encodes contents of the NSData object. |
|
41 |
// |
|
42 |
/// Returns: |
|
43 |
/// A new autoreleased NSData with the encoded payload. nil for any error. |
|
44 |
// |
|
45 |
+(NSData *)encodeData:(NSData *)data; |
|
46 |
|
|
47 |
// decodeData: |
|
48 |
// |
|
49 |
/// Base64 decodes contents of the NSData object. |
|
50 |
// |
|
51 |
/// Returns: |
|
52 |
/// A new autoreleased NSData with the decoded payload. nil for any error. |
|
53 |
// |
|
54 |
+(NSData *)decodeData:(NSData *)data; |
|
55 |
|
|
56 |
// encodeBytes:length: |
|
57 |
// |
|
58 |
/// Base64 encodes the data pointed at by |bytes|. |
|
59 |
// |
|
60 |
/// Returns: |
|
61 |
/// A new autoreleased NSData with the encoded payload. nil for any error. |
|
62 |
// |
|
63 |
+(NSData *)encodeBytes:(const void *)bytes length:(NSUInteger)length; |
|
64 |
|
|
65 |
// decodeBytes:length: |
|
66 |
// |
|
67 |
/// Base64 decodes the data pointed at by |bytes|. |
|
68 |
// |
|
69 |
/// Returns: |
|
70 |
/// A new autoreleased NSData with the encoded payload. nil for any error. |
|
71 |
// |
|
72 |
+(NSData *)decodeBytes:(const void *)bytes length:(NSUInteger)length; |
|
73 |
|
|
74 |
// stringByEncodingData: |
|
75 |
// |
|
76 |
/// Base64 encodes contents of the NSData object. |
|
77 |
// |
|
78 |
/// Returns: |
|
79 |
/// A new autoreleased NSString with the encoded payload. nil for any error. |
|
80 |
// |
|
81 |
+(NSString *)stringByEncodingData:(NSData *)data; |
|
82 |
|
|
83 |
// stringByEncodingBytes:length: |
|
84 |
// |
|
85 |
/// Base64 encodes the data pointed at by |bytes|. |
|
86 |
// |
|
87 |
/// Returns: |
|
88 |
/// A new autoreleased NSString with the encoded payload. nil for any error. |
|
89 |
// |
|
90 |
+(NSString *)stringByEncodingBytes:(const void *)bytes length:(NSUInteger)length; |
|
91 |
|
|
92 |
// decodeString: |
|
93 |
// |
|
94 |
/// Base64 decodes contents of the NSString. |
|
95 |
// |
|
96 |
/// Returns: |
|
97 |
/// A new autoreleased NSData with the decoded payload. nil for any error. |
|
98 |
// |
|
99 |
+(NSData *)decodeString:(NSString *)string; |
|
100 |
|
|
101 |
// |
|
102 |
// Modified Base64 encoding so the results can go onto urls. |
|
103 |
// |
|
104 |
// The changes are in the characters generated and also allows the result to |
|
105 |
// not be padded to a multiple of 4. |
|
106 |
// Must use the matching call to encode/decode, won't interop with the |
|
107 |
// RFC versions. |
|
108 |
// |
|
109 |
|
|
110 |
// webSafeEncodeData:padded: |
|
111 |
// |
|
112 |
/// WebSafe Base64 encodes contents of the NSData object. If |padded| is YES |
|
113 |
/// then padding characters are added so the result length is a multiple of 4. |
|
114 |
// |
|
115 |
/// Returns: |
|
116 |
/// A new autoreleased NSData with the encoded payload. nil for any error. |
|
117 |
// |
|
118 |
+(NSData *)webSafeEncodeData:(NSData *)data |
|
119 |
padded:(BOOL)padded; |
|
120 |
|
|
121 |
// webSafeDecodeData: |
|
122 |
// |
|
123 |
/// WebSafe Base64 decodes contents of the NSData object. |
|
124 |
// |
|
125 |
/// Returns: |
|
126 |
/// A new autoreleased NSData with the decoded payload. nil for any error. |
|
127 |
// |
|
128 |
+(NSData *)webSafeDecodeData:(NSData *)data; |
|
129 |
|
|
130 |
// webSafeEncodeBytes:length:padded: |
|
131 |
// |
|
132 |
/// WebSafe Base64 encodes the data pointed at by |bytes|. If |padded| is YES |
|
133 |
/// then padding characters are added so the result length is a multiple of 4. |
|
134 |
// |
|
135 |
/// Returns: |
|
136 |
/// A new autoreleased NSData with the encoded payload. nil for any error. |
|
137 |
// |
|
138 |
+(NSData *)webSafeEncodeBytes:(const void *)bytes |
|
139 |
length:(NSUInteger)length |
|
140 |
padded:(BOOL)padded; |
|
141 |
|
|
142 |
// webSafeDecodeBytes:length: |
|
143 |
// |
|
144 |
/// WebSafe Base64 decodes the data pointed at by |bytes|. |
|
145 |
// |
|
146 |
/// Returns: |
|
147 |
/// A new autoreleased NSData with the encoded payload. nil for any error. |
|
148 |
// |
|
149 |
+(NSData *)webSafeDecodeBytes:(const void *)bytes length:(NSUInteger)length; |
|
150 |
|
|
151 |
// stringByWebSafeEncodingData:padded: |
|
152 |
// |
|
153 |
/// WebSafe Base64 encodes contents of the NSData object. If |padded| is YES |
|
154 |
/// then padding characters are added so the result length is a multiple of 4. |
|
155 |
// |
|
156 |
/// Returns: |
|
157 |
/// A new autoreleased NSString with the encoded payload. nil for any error. |
|
158 |
// |
|
159 |
+(NSString *)stringByWebSafeEncodingData:(NSData *)data |
|
160 |
padded:(BOOL)padded; |
|
161 |
|
|
162 |
// stringByWebSafeEncodingBytes:length:padded: |
|
163 |
// |
|
164 |
/// WebSafe Base64 encodes the data pointed at by |bytes|. If |padded| is YES |
|
165 |
/// then padding characters are added so the result length is a multiple of 4. |
|
166 |
// |
|
167 |
/// Returns: |
|
168 |
/// A new autoreleased NSString with the encoded payload. nil for any error. |
|
169 |
// |
|
170 |
+(NSString *)stringByWebSafeEncodingBytes:(const void *)bytes |
|
171 |
length:(NSUInteger)length |
|
172 |
padded:(BOOL)padded; |
|
173 |
|
|
174 |
// webSafeDecodeString: |
|
175 |
// |
|
176 |
/// WebSafe Base64 decodes contents of the NSString. |
|
177 |
// |
|
178 |
/// Returns: |
|
179 |
/// A new autoreleased NSData with the decoded payload. nil for any error. |
|
180 |
// |
|
181 |
+(NSData *)webSafeDecodeString:(NSString *)string; |
|
182 |
|
|
183 |
@end |