Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / cdf / src / WCF / IdentityModel / System / IdentityModel / CanonicalFormWriter.cs / 1305376 / CanonicalFormWriter.cs
//------------------------------------------------------------ // Copyright (c) Microsoft Corporation. All rights reserved. //----------------------------------------------------------- namespace System.IdentityModel { using System.IO; using System.Security.Cryptography; using System.Text; using System.Xml; abstract class CanonicalFormWriter { internal static readonly UTF8Encoding Utf8WithoutPreamble = new UTF8Encoding(false); protected static void Base64EncodeAndWrite(Stream stream, byte[] workBuffer, char[] base64WorkBuffer, byte[] data) { if ((data.Length / 3) * 4 + 4 > base64WorkBuffer.Length) { EncodeAndWrite(stream, Convert.ToBase64String(data)); return; } int encodedLength = Convert.ToBase64CharArray(data, 0, data.Length, base64WorkBuffer, 0, Base64FormattingOptions.None); EncodeAndWrite(stream, workBuffer, base64WorkBuffer, encodedLength); } protected static void EncodeAndWrite(Stream stream, byte[] workBuffer, string s) { if (s.Length > workBuffer.Length) { EncodeAndWrite(stream, s); return; } for (int i = 0; i < s.Length; i++) { char c = s[i]; if (c < 127) { workBuffer[i] = (byte) c; } else { EncodeAndWrite(stream, s); return; } } stream.Write(workBuffer, 0, s.Length); } protected static void EncodeAndWrite(Stream stream, byte[] workBuffer, char[] chars) { EncodeAndWrite(stream, workBuffer, chars, chars.Length); } protected static void EncodeAndWrite(Stream stream, byte[] workBuffer, char[] chars, int count) { if (count > workBuffer.Length) { EncodeAndWrite(stream, chars, count); return; } for (int i = 0; i < count; i++) { char c = chars[i]; if (c < 127) { workBuffer[i] = (byte) c; } else { EncodeAndWrite(stream, chars, count); return; } } stream.Write(workBuffer, 0, count); } static void EncodeAndWrite(Stream stream, string s) { byte[] buffer = CanonicalFormWriter.Utf8WithoutPreamble.GetBytes(s); stream.Write(buffer, 0, buffer.Length); } static void EncodeAndWrite(Stream stream, char[] chars, int count) { byte[] buffer = CanonicalFormWriter.Utf8WithoutPreamble.GetBytes(chars, 0, count); stream.Write(buffer, 0, buffer.Length); } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. //------------------------------------------------------------ // Copyright (c) Microsoft Corporation. All rights reserved. //----------------------------------------------------------- namespace System.IdentityModel { using System.IO; using System.Security.Cryptography; using System.Text; using System.Xml; abstract class CanonicalFormWriter { internal static readonly UTF8Encoding Utf8WithoutPreamble = new UTF8Encoding(false); protected static void Base64EncodeAndWrite(Stream stream, byte[] workBuffer, char[] base64WorkBuffer, byte[] data) { if ((data.Length / 3) * 4 + 4 > base64WorkBuffer.Length) { EncodeAndWrite(stream, Convert.ToBase64String(data)); return; } int encodedLength = Convert.ToBase64CharArray(data, 0, data.Length, base64WorkBuffer, 0, Base64FormattingOptions.None); EncodeAndWrite(stream, workBuffer, base64WorkBuffer, encodedLength); } protected static void EncodeAndWrite(Stream stream, byte[] workBuffer, string s) { if (s.Length > workBuffer.Length) { EncodeAndWrite(stream, s); return; } for (int i = 0; i < s.Length; i++) { char c = s[i]; if (c < 127) { workBuffer[i] = (byte) c; } else { EncodeAndWrite(stream, s); return; } } stream.Write(workBuffer, 0, s.Length); } protected static void EncodeAndWrite(Stream stream, byte[] workBuffer, char[] chars) { EncodeAndWrite(stream, workBuffer, chars, chars.Length); } protected static void EncodeAndWrite(Stream stream, byte[] workBuffer, char[] chars, int count) { if (count > workBuffer.Length) { EncodeAndWrite(stream, chars, count); return; } for (int i = 0; i < count; i++) { char c = chars[i]; if (c < 127) { workBuffer[i] = (byte) c; } else { EncodeAndWrite(stream, chars, count); return; } } stream.Write(workBuffer, 0, count); } static void EncodeAndWrite(Stream stream, string s) { byte[] buffer = CanonicalFormWriter.Utf8WithoutPreamble.GetBytes(s); stream.Write(buffer, 0, buffer.Length); } static void EncodeAndWrite(Stream stream, char[] chars, int count) { byte[] buffer = CanonicalFormWriter.Utf8WithoutPreamble.GetBytes(chars, 0, count); stream.Write(buffer, 0, buffer.Length); } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007.
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- ClientConfigurationHost.cs
- DispatchWrapper.cs
- SharedDp.cs
- SerializationException.cs
- DataMemberConverter.cs
- MenuItem.cs
- MsmqIntegrationValidationBehavior.cs
- DataPagerFieldCollection.cs
- StreamInfo.cs
- SafePEFileHandle.cs
- MailAddress.cs
- WebBrowserUriTypeConverter.cs
- ISFTagAndGuidCache.cs
- SqlError.cs
- FormViewPageEventArgs.cs
- Compiler.cs
- BuildTopDownAttribute.cs
- DelegateBodyWriter.cs
- BindingSource.cs
- Substitution.cs
- RuleInfoComparer.cs
- InternalSafeNativeMethods.cs
- PeerNearMe.cs
- FlowDocumentView.cs
- SystemColors.cs
- EventProxy.cs
- CategoryAttribute.cs
- TouchDevice.cs
- VirtualDirectoryMappingCollection.cs
- ObjectDataSourceDisposingEventArgs.cs
- DashStyle.cs
- WindowsClientElement.cs
- UniqueConstraint.cs
- CacheSection.cs
- SafeFreeMibTable.cs
- BmpBitmapDecoder.cs
- DataServiceHost.cs
- PropertyGridEditorPart.cs
- ExpressionCopier.cs
- BasicExpressionVisitor.cs
- SubclassTypeValidator.cs
- SslStreamSecurityElement.cs
- CultureTableRecord.cs
- NameTable.cs
- ApplicationException.cs
- X509Certificate.cs
- BindingWorker.cs
- DBCommand.cs
- QuadraticBezierSegment.cs
- ColorKeyFrameCollection.cs
- ToolStripRenderEventArgs.cs
- SqlMethods.cs
- TreeView.cs
- ImageListUtils.cs
- HttpConfigurationSystem.cs
- ObjectDataSourceDesigner.cs
- IISMapPath.cs
- SectionInput.cs
- Point3DAnimation.cs
- CannotUnloadAppDomainException.cs
- ObjectResult.cs
- ChameleonKey.cs
- ColorBlend.cs
- Environment.cs
- AsyncDataRequest.cs
- Hex.cs
- ApplicationFileParser.cs
- DefaultTextStore.cs
- TreeViewEvent.cs
- ActivityInstanceReference.cs
- InertiaExpansionBehavior.cs
- CharacterShapingProperties.cs
- SystemUnicastIPAddressInformation.cs
- FrameDimension.cs
- OperationCanceledException.cs
- _NtlmClient.cs
- ConditionedDesigner.cs
- XmlSchemaChoice.cs
- DodSequenceMerge.cs
- Message.cs
- StorageTypeMapping.cs
- exports.cs
- GridViewCancelEditEventArgs.cs
- EmptyCollection.cs
- LinqDataSourceDisposeEventArgs.cs
- PeerApplication.cs
- IPAddress.cs
- hwndwrapper.cs
- DataGridItemAutomationPeer.cs
- ISO2022Encoding.cs
- ErrorReporting.cs
- ApplicationActivator.cs
- SurrogateEncoder.cs
- ObjectDataSourceStatusEventArgs.cs
- TypeSemantics.cs
- CardSpaceException.cs
- PolygonHotSpot.cs
- DeferredTextReference.cs
- SchemaCreator.cs
- BindableTemplateBuilder.cs