@@ -136,16 +136,16 @@ public static string Base64UrlEncode(byte[] input, int offset, int count, bool o
136
136
#if NETCOREAPP
137
137
return Base64UrlEncode ( input . AsSpan ( offset , count ) , omitPadding ) ;
138
138
#else
139
- // Special-case empty input
140
- if ( count == 0 )
141
- {
142
- return string . Empty ;
143
- }
139
+ // Special-case empty input
140
+ if ( count == 0 )
141
+ {
142
+ return string . Empty ;
143
+ }
144
144
145
- var buffer = new char [ GetArraySizeRequiredToEncode ( count ) ] ;
146
- var numBase64Chars = Base64UrlEncode ( input , offset , buffer , outputOffset : 0 , count : count , omitPadding ) ;
145
+ var buffer = new char [ GetArraySizeRequiredToEncode ( count ) ] ;
146
+ var numBase64Chars = Base64UrlEncode ( input , offset , buffer , outputOffset : 0 , count : count , omitPadding ) ;
147
147
148
- return new string ( buffer , startIndex : 0 , length : numBase64Chars ) ;
148
+ return new string ( buffer , startIndex : 0 , length : numBase64Chars ) ;
149
149
#endif
150
150
}
151
151
@@ -193,37 +193,37 @@ public static int Base64UrlEncode(byte[] input, int offset, char[] output, int o
193
193
#if NETCOREAPP
194
194
return Base64UrlEncode ( input . AsSpan ( offset , count ) , output . AsSpan ( outputOffset ) , omitPadding ) ;
195
195
#else
196
- // Special-case empty input.
197
- if ( count == 0 )
198
- {
199
- return 0 ;
200
- }
196
+ // Special-case empty input.
197
+ if ( count == 0 )
198
+ {
199
+ return 0 ;
200
+ }
201
201
202
- // Use base64url encoding with no padding characters. See RFC 4648, Sec. 5.
202
+ // Use base64url encoding with no padding characters. See RFC 4648, Sec. 5.
203
203
204
- // Start with default Base64 encoding.
205
- var numBase64Chars = Convert . ToBase64CharArray ( input , offset , count , output , outputOffset ) ;
204
+ // Start with default Base64 encoding.
205
+ var numBase64Chars = Convert . ToBase64CharArray ( input , offset , count , output , outputOffset ) ;
206
206
207
- // Fix up '+' -> '-' and '/' -> '_'. Drop padding characters.
208
- for ( var i = outputOffset ; i - outputOffset < numBase64Chars ; i ++ )
207
+ // Fix up '+' -> '-' and '/' -> '_'. Drop padding characters.
208
+ for ( var i = outputOffset ; i - outputOffset < numBase64Chars ; i ++ )
209
+ {
210
+ var ch = output [ i ] ;
211
+ if ( ch == '+' )
212
+ {
213
+ output [ i ] = '-' ;
214
+ }
215
+ else if ( ch == '/' )
209
216
{
210
- var ch = output [ i ] ;
211
- if ( ch == '+' )
212
- {
213
- output [ i ] = '-' ;
214
- }
215
- else if ( ch == '/' )
216
- {
217
- output [ i ] = '_' ;
218
- }
219
- else if ( omitPadding && ch == '=' )
220
- {
221
- // We've reached a padding character; truncate the remainder.
222
- return i - outputOffset ;
223
- }
217
+ output [ i ] = '_' ;
224
218
}
219
+ else if ( omitPadding && ch == '=' )
220
+ {
221
+ // We've reached a padding character; truncate the remainder.
222
+ return i - outputOffset ;
223
+ }
224
+ }
225
225
226
- return numBase64Chars ;
226
+ return numBase64Chars ;
227
227
#endif
228
228
}
229
229
0 commit comments