Beispiel #1
0
        InitForOpen()
        {
            StreamInfo siPackage = new StreamInfo(_root, PackageStreamName);

            if (!siPackage.InternalExists())
            {
                throw new FileFormatException(SR.PackageNotFound);
            }

            //If the StreamInfo exists we go on to check if correct transform has been
            //applied to the Stream

            DataSpaceManager dsm = _root.GetDataSpaceManager();

            List <IDataTransform> transforms = dsm.GetTransformsForStreamInfo(siPackage);

            RightsManagementEncryptionTransform rmet = null;

            foreach (IDataTransform dataTransform in transforms)
            {
                string id = dataTransform.TransformIdentifier as string;
                if (id != null &&
                    String.CompareOrdinal(id.ToUpperInvariant(),
                                          RightsManagementEncryptionTransform.ClassTransformIdentifier.ToUpperInvariant()) == 0)
                {
                    // Do not allow more than one RM Transform
                    if (rmet != null)
                    {
                        throw new FileFormatException(SR.MultipleRightsManagementEncryptionTransformFound);
                    }

                    rmet = dataTransform as RightsManagementEncryptionTransform;
                }
            }

            if (rmet == null)
            {
                throw new FileFormatException(SR.RightsManagementEncryptionTransformNotFound);
            }

            //
            //  There is no reason to further push initialization of the Rights Management
            //  data (parsing publish / use license). It will add unnecessary costs to the
            //  scenarios where RM license are not relevant, for example indexing and
            //  working with document properties
            //

            //
            // Make the rights management information stored in the compound file
            // available to the application through the RightsManagementInformation
            // property.
            //
            _rmi = new RightsManagementInformation(rmet);
        }
Beispiel #2
0
        InitializeRMForCreate(
            PublishLicense publishLicense,
            CryptoProvider cryptoProvider
            )
        {
            //
            // Define a data space consisting of a single transform, namely the
            // RightsManagementEncryptionTransform.
            //
            DataSpaceManager dsm = _root.GetDataSpaceManager();

            dsm.DefineTransform(
                RightsManagementEncryptionTransform.ClassTransformIdentifier,
                EncryptionTransformName
                );

            string[] transformStack = new string[1];
            transformStack[0] = EncryptionTransformName;
            _dataSpaceName    = DataspaceLabelRMEncryptionNoCompression;
            dsm.DefineDataSpace(transformStack, _dataSpaceName);

            //
            // The call to DefineTransform created a RightsManagementEncryptionTransform
            // object. Obtain this object from the DataSpaceManager, and wrap it in a
            // RightsManagementInformation object. This makes the RM information in the
            // compound file available to the application (through the RightsManagementInformation
            // property), without exposing to the application the implementation detail
            // that there -is- such a thing as a "transform".
            //
            RightsManagementEncryptionTransform rmet =
                dsm.GetTransformFromName(EncryptionTransformName) as RightsManagementEncryptionTransform;

            //
            // We just defined this transform, so it must exist.
            //
            Debug.Assert(
                rmet != null,
                "RightsManagementEncryptionTransform not found"
                );

            _rmi = new RightsManagementInformation(rmet);

            //
            // Prepare the transform object for use.
            //
            rmet.SavePublishLicense(publishLicense);
            rmet.CryptoProvider = cryptoProvider;

            //
            // The transform object is now ready for use. When the data space manager
            // queries the transform's IsReady property, it will return true. So there
            // is no need to sign up for the TransformInitializationEvent.
            //
        }
Beispiel #3
0
        InitForOpen()
        {

            StreamInfo siPackage = new StreamInfo(_root, PackageStreamName); 
            if (!siPackage.InternalExists())
            { 
                throw new FileFormatException(SR.Get(SRID.PackageNotFound)); 
            }
 
            //If the StreamInfo exists we go on to check if correct transform has been
            //applied to the Stream

            DataSpaceManager dsm = _root.GetDataSpaceManager(); 

            List<IDataTransform> transforms = dsm.GetTransformsForStreamInfo(siPackage); 
 
            RightsManagementEncryptionTransform rmet = null;
 
            foreach (IDataTransform dataTransform in transforms)
            {
                string id = dataTransform.TransformIdentifier as string;
                if (id != null && 
                        String.CompareOrdinal(id.ToUpperInvariant(),
                            RightsManagementEncryptionTransform.ClassTransformIdentifier.ToUpperInvariant()) == 0) 
                { 
                    // Do not allow more than one RM Transform
                    if (rmet != null) 
                    {
                        throw new FileFormatException(SR.Get(SRID.MultipleRightsManagementEncryptionTransformFound));
                    }
 
                    rmet = dataTransform as RightsManagementEncryptionTransform;
                } 
            } 

            if (rmet == null) 
            {
                throw new FileFormatException(SR.Get(SRID.RightsManagementEncryptionTransformNotFound));
            }
 
            //
            //  There is no reason to further push initialization of the Rights Management 
            //  data (parsing publish / use license). It will add unnecessary costs to the 
            //  scenarios where RM license are not relevant, for example indexing and
            //  working with document properties 
            //

            //
            // Make the rights management information stored in the compound file 
            // available to the application through the RightsManagementInformation
            // property. 
            // 
            _rmi = new RightsManagementInformation(rmet);
        } 
Beispiel #4
0
        InitializeRMForCreate(
            PublishLicense publishLicense, 
            CryptoProvider cryptoProvider
            )
        {
            // 
            // Define a data space consisting of a single transform, namely the
            // RightsManagementEncryptionTransform. 
            // 
            DataSpaceManager dsm = _root.GetDataSpaceManager();
 
            dsm.DefineTransform(
                    RightsManagementEncryptionTransform.ClassTransformIdentifier,
                    EncryptionTransformName
                    ); 

            string[] transformStack = new string[1]; 
            transformStack[0] = EncryptionTransformName; 
            _dataSpaceName = DataspaceLabelRMEncryptionNoCompression;
            dsm.DefineDataSpace(transformStack, _dataSpaceName); 

            //
            // The call to DefineTransform created a RightsManagementEncryptionTransform
            // object. Obtain this object from the DataSpaceManager, and wrap it in a 
            // RightsManagementInformation object. This makes the RM information in the
            // compound file available to the application (through the RightsManagementInformation 
            // property), without exposing to the application the implementation detail 
            // that there -is- such a thing as a "transform".
            // 
            RightsManagementEncryptionTransform rmet =
                dsm.GetTransformFromName(EncryptionTransformName) as RightsManagementEncryptionTransform;

            // 
            // We just defined this transform, so it must exist.
            // 
            Debug.Assert( 
                rmet != null,
                "RightsManagementEncryptionTransform not found" 
                );

            _rmi = new RightsManagementInformation(rmet);
 
            //
            // Prepare the transform object for use. 
            // 
            rmet.SavePublishLicense(publishLicense);
            rmet.CryptoProvider = cryptoProvider; 

            //
            // The transform object is now ready for use. When the data space manager
            // queries the transform's IsReady property, it will return true. So there 
            // is no need to sign up for the TransformInitializationEvent.
            // 
        }