EncryptedPackageEnvelope( Stream envelopeStream, PublishLicense publishLicense, CryptoProvider cryptoProvider ) { if (envelopeStream == null) { throw new ArgumentNullException("envelopeStream"); } ThrowIfRMEncryptionInfoInvalid(publishLicense, cryptoProvider); _root = StorageRoot.CreateOnStream(envelopeStream, _defaultFileModeForCreate); // // CreateOnStream opens the stream for read access if it's readable, and for // read/write access if it's writable. We're going to need it to be writable, // so check that it is. // if (_root.OpenAccess != FileAccess.ReadWrite) { throw new NotSupportedException(SR.StreamNeedsReadWriteAccess); } InitializeRMForCreate(publishLicense, cryptoProvider); EmbedPackage(null); }
EncryptedPackageEnvelope( Stream envelopeStream ) { if (envelopeStream == null) { throw new ArgumentNullException("envelopeStream"); } _root = StorageRoot.CreateOnStream(envelopeStream, _defaultFileModeForOpen); InitForOpen(); }
IsEncryptedPackageEnvelope( Stream stream ) { if (stream == null) { throw new ArgumentNullException("stream"); } bool retval = false; StorageRoot root = null; try { // // When StorageRoot.CreateOnStream is called on a stream that is not // a storage object, it throws an IOException whose inner exception is // a COMException whose error code is 0x80030050, STG_E_FILEALREADYEXISTS. // Check for that case and return false because that means that this // stream is not an RM-protected file. // // Any other exception is a real error. // root = StorageRoot.CreateOnStream(stream, FileMode.Open); // // It's a compound file. Does it contain an "EncryptedPackage" stream? // retval = ContainsEncryptedPackageStream(root); } catch (IOException ex) { COMException comException = ex.InnerException as COMException; if (comException != null && comException.ErrorCode == STG_E_FILEALREADYEXISTS) { return(false); } throw; // Any other kind of IOException is a real error. } finally { if (root != null) { root.Close(); } } return(retval); }