/// <summary>Reads a SASL negotiation message and negotiation cipher options.</summary> /// <param name="in">stream to read</param> /// <param name="cipherOptions">list to store negotiation cipher options</param> /// <returns>byte[] SASL negotiation message</returns> /// <exception cref="System.IO.IOException">for any error</exception> public static byte[] ReadSaslMessageAndNegotiationCipherOptions(InputStream @in, IList <CipherOption> cipherOptions) { DataTransferProtos.DataTransferEncryptorMessageProto proto = DataTransferProtos.DataTransferEncryptorMessageProto .ParseFrom(PBHelper.VintPrefixed(@in)); if (proto.GetStatus() == DataTransferProtos.DataTransferEncryptorMessageProto.DataTransferEncryptorStatus .ErrorUnknownKey) { throw new InvalidEncryptionKeyException(proto.GetMessage()); } else { if (proto.GetStatus() == DataTransferProtos.DataTransferEncryptorMessageProto.DataTransferEncryptorStatus .Error) { throw new IOException(proto.GetMessage()); } else { IList <HdfsProtos.CipherOptionProto> optionProtos = proto.GetCipherOptionList(); if (optionProtos != null) { foreach (HdfsProtos.CipherOptionProto optionProto in optionProtos) { cipherOptions.AddItem(PBHelper.Convert(optionProto)); } } return(proto.GetPayload().ToByteArray()); } } }
/// <summary>Read SASL message and negotiated cipher option from server.</summary> /// <param name="in">stream to read</param> /// <returns> /// SaslResponseWithNegotiatedCipherOption SASL message and /// negotiated cipher option /// </returns> /// <exception cref="System.IO.IOException">for any error</exception> public static SaslResponseWithNegotiatedCipherOption ReadSaslMessageAndNegotiatedCipherOption (InputStream @in) { DataTransferProtos.DataTransferEncryptorMessageProto proto = DataTransferProtos.DataTransferEncryptorMessageProto .ParseFrom(PBHelper.VintPrefixed(@in)); if (proto.GetStatus() == DataTransferProtos.DataTransferEncryptorMessageProto.DataTransferEncryptorStatus .ErrorUnknownKey) { throw new InvalidEncryptionKeyException(proto.GetMessage()); } else { if (proto.GetStatus() == DataTransferProtos.DataTransferEncryptorMessageProto.DataTransferEncryptorStatus .Error) { throw new IOException(proto.GetMessage()); } else { byte[] response = proto.GetPayload().ToByteArray(); IList <CipherOption> options = PBHelper.ConvertCipherOptionProtos(proto.GetCipherOptionList ()); CipherOption option = null; if (options != null && !options.IsEmpty()) { option = options[0]; } return(new SaslResponseWithNegotiatedCipherOption(response, option)); } } }
/// <summary>Reads a SASL negotiation message.</summary> /// <param name="in">stream to read</param> /// <returns>bytes of SASL negotiation messsage</returns> /// <exception cref="System.IO.IOException">for any error</exception> public static byte[] ReadSaslMessage(InputStream @in) { DataTransferProtos.DataTransferEncryptorMessageProto proto = DataTransferProtos.DataTransferEncryptorMessageProto .ParseFrom(PBHelper.VintPrefixed(@in)); if (proto.GetStatus() == DataTransferProtos.DataTransferEncryptorMessageProto.DataTransferEncryptorStatus .ErrorUnknownKey) { throw new InvalidEncryptionKeyException(proto.GetMessage()); } else { if (proto.GetStatus() == DataTransferProtos.DataTransferEncryptorMessageProto.DataTransferEncryptorStatus .Error) { throw new IOException(proto.GetMessage()); } else { return(proto.GetPayload().ToByteArray()); } } }