Code:
/ DotNET / DotNET / 8.0 / untmp / WIN_WINDOWS / lh_tools_devdiv_wpf / Windows / wcp / TrustUi / MS / Internal / documents / Application / RightsDocument.cs / 1 / RightsDocument.cs
using System.IO;
using System.IO.Packaging;
using System.Security;
using System.Security.RightsManagement;
using MS.Internal.Permissions; // For CompoundFileIOPermission
namespace MS.Internal.Documents.Application
{
///
/// Extends StreamDocument with EncryptedPackageEnvelope for use by RightsController.
///
internal class RightsDocument : StreamDocument
{
#region Constructors
//--------------------------------------------------------------------------
// Constructors
//-------------------------------------------------------------------------
///
/// Constructs a FileDocument allowing for a dependency.
///
/// The Document this object depends on.
internal RightsDocument(Document dependency)
: base(dependency) { }
#endregion Constructors
#region Internal Methods
//-------------------------------------------------------------------------
// Internal Methods
//-------------------------------------------------------------------------
///
/// Returns true when the destination stream is an encrypted package envelope.
///
///
/// Critical:
/// 1) asserts for CompoundFileIOPermission
/// TreatAsSafe:
/// 1) data into assert comes from critical for set destination stream
///
[SecurityCritical, SecurityTreatAsSafe]
internal bool IsDestinationProtected()
{
if (DestinationPackage != null)
{
return true;
}
Stream destinationStream = this.Dependency.Destination;
(new CompoundFileIOPermission()).Assert(); // BlessedAssert
try
{
return EncryptedPackageEnvelope.IsEncryptedPackageEnvelope(
destinationStream);
}
finally
{
CompoundFileIOPermission.RevertAssert();
}
}
///
/// Returns true when the source stream is an encrypted package envelope.
///
///
/// Critical:
/// 1) asserts for CompoundFileIOPermission
/// TreatAsSafe:
/// 1) data into assert comes from critical for set destination stream
///
[SecurityCritical, SecurityTreatAsSafe]
internal bool IsSourceProtected()
{
if (SourcePackage != null)
{
return true;
}
Stream sourceStream = this.Dependency.Source;
(new CompoundFileIOPermission()).Assert(); // BlessedAssert
try
{
return EncryptedPackageEnvelope.IsEncryptedPackageEnvelope(
sourceStream);
}
finally
{
CompoundFileIOPermission.RevertAssert();
}
}
#endregion Internal Methods
#region Internal Properties
//--------------------------------------------------------------------------
// Internal Properties
//-------------------------------------------------------------------------
///
/// The EncryptedPackageEnvelope used for the destination document.
/// This value may be null when the document is not rights protected.
///
///
/// Critical for set
/// 1) property accessor for critical for set object
///
internal EncryptedPackageEnvelope DestinationPackage
{
get { return _destination.Value; }
[SecurityCritical]
set { _destination.Value = value; }
}
///
/// The EncryptedPackageEnvelope used for the source document.
/// This value may be null when the document is not rights protected.
///
///
/// Critical for set
/// 1) property accessor for critical for set object
///
internal EncryptedPackageEnvelope SourcePackage
{
get { return _source.Value; }
[SecurityCritical]
set { _source.Value = value; }
}
///
/// The EncryptedPackageEnvelope used for the working document.
/// This value may be null when the document is not rights protected.
///
///
/// Critical for set
/// 1) property accessor for critical for set object
///
internal EncryptedPackageEnvelope WorkspacePackage
{
get { return _workspace.Value; }
[SecurityCritical]
set { _workspace.Value = value; }
}
#endregion Internal Properties
#region IDisposable Members
//--------------------------------------------------------------------------
// IDisposable Members
//--------------------------------------------------------------------------
///
///
///
///
/// Critical:
/// 1) asserts for CompoundFileIOPermission
/// 2) sets SourcePackage, DestinationPackage, and WorkspacePackage to null
/// TreatAsSafe:
/// 1) data into asserts (package objects) are critical for set
/// 2) critical for set packages are set to null, which is what should
/// happen on dispose
///
[SecurityCritical, SecurityTreatAsSafe]
protected override void Dispose(bool disposing)
{
try
{
if (disposing)
{
// our base is StreamDocument, as these packages support
// the stream we want our base to release them first
ReleaseStreams();
// The only code that actually requires this assert are the
// calls to Close. Regardless I've put the assert around the
// whole block since the rest of the code under it is almost
// all just checking packages for null or setting them to null.
// This is much cleaner than having three separate asserts (and
// three more try/finally blocks) for each Close call.
(new CompoundFileIOPermission()).Assert(); //BlessedAssert
try
{
try
{
if (DestinationPackage != null)
{
if (DestinationPackage == SourcePackage)
{
SourcePackage = null;
}
DestinationPackage.Close();
DestinationPackage = null;
}
}
finally
{
try
{
if (WorkspacePackage != null)
{
WorkspacePackage.Close();
WorkspacePackage = null;
}
}
finally
{
if (SourcePackage != null)
{
SourcePackage.Close();
SourcePackage = null;
}
}
}
}
finally
{
CompoundFileIOPermission.RevertAssert();
}
}
}
finally
{
base.Dispose(disposing);
}
}
#endregion IDisposable Members
#region Private Fields
//-------------------------------------------------------------------------
// Private Fields
//--------------------------------------------------------------------------
///
/// This is critical for set because we assert and perform critical
/// operations on the encrypted package envelope.
///
private SecurityCriticalDataForSet _source;
///
/// This is critical for set because we assert and perform critical
/// operations on the encrypted package envelope.
///
private SecurityCriticalDataForSet _workspace;
///
/// This is critical for set because we assert and perform critical
/// operations on the encrypted package envelope.
///
private SecurityCriticalDataForSet _destination;
#endregion Private Fields
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
// Copyright (c) Microsoft Corporation. All rights reserved.
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- CanonicalXml.cs
- ArraySortHelper.cs
- XmlNode.cs
- KoreanCalendar.cs
- TableSectionStyle.cs
- FormViewInsertEventArgs.cs
- ExcCanonicalXml.cs
- TailCallAnalyzer.cs
- PointLightBase.cs
- AlphabeticalEnumConverter.cs
- GetReadStreamResult.cs
- Vertex.cs
- TextSchema.cs
- HttpWebResponse.cs
- LoginStatusDesigner.cs
- SafeFileMappingHandle.cs
- NameSpaceExtractor.cs
- SQLBytes.cs
- ChangePassword.cs
- WebScriptMetadataFormatter.cs
- SimpleBitVector32.cs
- DataGridRowsPresenter.cs
- WindowsPen.cs
- Timer.cs
- TlsSspiNegotiation.cs
- ClientTargetSection.cs
- SizeAnimationBase.cs
- FileReader.cs
- LayoutTableCell.cs
- ConfigurationConverterBase.cs
- ForceCopyBuildProvider.cs
- XmlSchemaProviderAttribute.cs
- Base64Stream.cs
- ValidatorAttribute.cs
- JsonServiceDocumentSerializer.cs
- StringDictionaryWithComparer.cs
- ComponentDispatcherThread.cs
- RoutedEvent.cs
- XPathNodeList.cs
- OperationContext.cs
- DesignerAttribute.cs
- TemplateManager.cs
- ManifestResourceInfo.cs
- PolyLineSegment.cs
- DesignerOptionService.cs
- Delay.cs
- BCryptHashAlgorithm.cs
- EdmProviderManifest.cs
- HyperLinkColumn.cs
- UIElementHelper.cs
- TypeBuilder.cs
- CodeLabeledStatement.cs
- ToolStripDropTargetManager.cs
- RemotingException.cs
- UserPreferenceChangingEventArgs.cs
- StorageAssociationSetMapping.cs
- SecurityHelper.cs
- StatusCommandUI.cs
- ADMembershipUser.cs
- MultiAsyncResult.cs
- EncoderReplacementFallback.cs
- ApplicationServiceHelper.cs
- DataGridItem.cs
- WebBrowserNavigatedEventHandler.cs
- InvariantComparer.cs
- UrlMappingsSection.cs
- InvokeFunc.cs
- ExpressionReplacer.cs
- DefaultValidator.cs
- DBSqlParserColumn.cs
- ContextQuery.cs
- Command.cs
- GenericEnumerator.cs
- FunctionQuery.cs
- wgx_render.cs
- smtpconnection.cs
- versioninfo.cs
- SpStreamWrapper.cs
- XmlElement.cs
- InputLangChangeEvent.cs
- DataStreamFromComStream.cs
- RegexNode.cs
- shaper.cs
- XmlSchemaAttribute.cs
- ContentPresenter.cs
- SessionEndingCancelEventArgs.cs
- MarginsConverter.cs
- linebase.cs
- Transform.cs
- path.cs
- ObjectReaderCompiler.cs
- JsonByteArrayDataContract.cs
- InkCanvasSelection.cs
- OrderedDictionary.cs
- AstNode.cs
- KeyValuePairs.cs
- WebControlParameterProxy.cs
- IPEndPoint.cs
- ObjectDataSourceMethodEventArgs.cs
- BamlReader.cs