protected int TakeAction(IKeySet keyset, Stream inStream, Stream outStream, Stream outStream2, IKeySet keyset2) { if ((WireFormat.IsNullOrEmpty(_format) && (keyset.Metadata.Purpose == KeyPurpose.DecryptAndEncrypt || keyset.Metadata.Purpose == KeyPurpose.Encrypt)) || _format == WireFormat.Crypt ) { using (var ucrypter = new Encrypter(keyset)) { var err = UseCompression(ucrypter); if (err != 0) { return(err); } ucrypter.Encrypt(inStream, outStream); } } else if (WireFormat.IsNullOrEmpty(_format) || _format == WireFormat.Sign) { using (var signer = new Signer(keyset)) { var sig = signer.Sign(inStream); outStream.Write(sig, 0, sig.Length); } } else if (_format == WireFormat.SignTimeout) { using (var signer = new TimeoutSigner(keyset)) { var sig = signer.Sign(inStream, _expires.GetValueOrDefault()); outStream.Write(sig, 0, sig.Length); } } else if (_format == WireFormat.SignAttached) { using (var signer = new AttachedSigner(keyset)) { byte[] hidden = null; if (!String.IsNullOrWhiteSpace(_attachedHidden)) { hidden = Keyczar.Keyczar.RawStringEncoding.GetBytes(_attachedHidden); } signer.Sign(inStream, outStream, hidden); } } else if (_format == WireFormat.SignVanilla || _format == WireFormat.SignUnversioned) { using (var signer = new Keyczar.Compat.VanillaSigner(keyset)) { var sig = signer.Sign(inStream); outStream.Write(sig, 0, sig.Length); } } else if (_format == WireFormat.CryptSession) { using (var crypter = new Encrypter(keyset)) using (var sessionCrypter = new SessionCrypter(crypter)) { var err = UseCompression(sessionCrypter); if (err != 0) { return(err); } var materials = sessionCrypter.SessionMaterial.ToBytes(); outStream.Write(materials, 0, materials.Length); sessionCrypter.Encrypt(inStream, outStream2); } } else if (_format == WireFormat.CryptSignedSession) { if (keyset2 == null) { Console.WriteLine(Localized.MsgRequiresLocation2); return(-1); } using (var crypter = new Encrypter(keyset)) using (var signer = new AttachedSigner(keyset2)) using (var sessionCrypter = new SessionCrypter(crypter, signer)) { var err = UseCompression(sessionCrypter); if (err != 0) { return(err); } var materials = sessionCrypter.SessionMaterial.ToBytes(); outStream.Write(materials, 0, materials.Length); sessionCrypter.Encrypt(inStream, outStream2); } } else { Console.WriteLine(Localized.MsgUnknownFormat, _format); return(-1); } return(0); }