//------------------------------------------------------
        //
        // Private Methods
        //
        //------------------------------------------------------

        #region Private Methods

        /// <summary>
        /// Load the contents of the dictionary from the compound file.
        /// </summary>
        /// <param name="rmet">
        /// The object that knows how to load use license data from the compound file.
        /// </param>
        /// <exception cref="ArgumentNullException">
        /// If <paramref name="rmet"/> is null.
        /// </exception>
        private void Load(RightsManagementEncryptionTransform rmet)
        {
            rmet.EnumUseLicenseStreams(
                new RightsManagementEncryptionTransform.UseLicenseStreamCallback(
                    this.AddUseLicenseFromStreamToDictionary
                    ),
                null
                );
        }
Example #2
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);
        }
Example #3
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.
            //
        }
        //------------------------------------------------------
        //
        // Constructors
        //
        //------------------------------------------------------

        #region Constructors

        /// <summary>
        /// Constructor.
        /// </summary>
        internal UserUseLicenseDictionaryLoader(RightsManagementEncryptionTransform rmet)
        {
            _dict = new Dictionary <ContentUser, UseLicense>(ContentUser._contentUserComparer);

            //
            // This constructor is only called from RightsManagementEncryptionTransform
            // .GetEmbeddedUseLicenses. That method passes "this" as the parameter.
            // So it can't possibly be null.
            //
            Invariant.Assert(rmet != null);

            Load(rmet);
        }
        AddUseLicenseFromStreamToDictionary(
            RightsManagementEncryptionTransform rmet,
            StreamInfo si,
            object param,
            ref bool stop
            )
        {
            ContentUser user;

            using (Stream stream = si.GetStream(FileMode.Open, FileAccess.Read))
            {
                using (BinaryReader utf8Reader = new BinaryReader(stream, _utf8Encoding))
                {
                    UseLicense useLicense = rmet.LoadUseLicenseAndUserFromStream(utf8Reader, out user);

                    _dict.Add(user, useLicense);
                }
            }
        }
 RightsManagementInformation(
     RightsManagementEncryptionTransform rmet
     )
 {
     _rmet = rmet;
 }