/** * Reads a SASL negotiation message and negotiation cipher options. * * @param in stream to read * @param cipherOptions list to store negotiation cipher options * @return byte[] SASL negotiation message * @throws IOException for any error */ public static byte[] readSaslMessageAndNegotiationCipherOptions( InputStream in, List<CipherOption> cipherOptions) throws IOException { DataTransferEncryptorMessageProto proto = DataTransferEncryptorMessageProto.parseFrom(vintPrefixed(in)); if (proto.getStatus() == DataTransferEncryptorStatus.ERROR_UNKNOWN_KEY) { throw new InvalidEncryptionKeyException(proto.getMessage()); } else if (proto.getStatus() == DataTransferEncryptorStatus.ERROR) { throw new IOException(proto.getMessage()); } else { List<CipherOptionProto> optionProtos = proto.getCipherOptionList(); if (optionProtos != null) { for (CipherOptionProto optionProto : optionProtos) { cipherOptions.add(PBHelper.convert(optionProto)); } } return proto.getPayload().toByteArray(); } }
public static CipherOptionProto convert(CipherOption option) { if (option != null) { CipherOptionProto.Builder builder = CipherOptionProto. newBuilder(); if (option.getCipherSuite() != null) { builder.setSuite(convert(option.getCipherSuite())); } if (option.getInKey() != null) { builder.setInKey(ByteString.copyFrom(option.getInKey())); } if (option.getInIv() != null) { builder.setInIv(ByteString.copyFrom(option.getInIv())); } if (option.getOutKey() != null) { builder.setOutKey(ByteString.copyFrom(option.getOutKey())); } if (option.getOutIv() != null) { builder.setOutIv(ByteString.copyFrom(option.getOutIv())); } return builder.build(); } return null; }
public static CipherOption convert(CipherOptionProto proto) { if (proto != null) { CipherSuite suite = null; if (proto.getSuite() != null) { suite = convert(proto.getSuite()); } byte[] inKey = null; if (proto.getInKey() != null) { inKey = proto.getInKey().toByteArray(); } byte[] inIv = null; if (proto.getInIv() != null) { inIv = proto.getInIv().toByteArray(); } byte[] outKey = null; if (proto.getOutKey() != null) { outKey = proto.getOutKey().toByteArray(); } byte[] outIv = null; if (proto.getOutIv() != null) { outIv = proto.getOutIv().toByteArray(); } return new CipherOption(suite, inKey, inIv, outKey, outIv); } return null; }
/** * Reads a SASL negotiation message and negotiation cipher options. * * @param in stream to read * @param cipherOptions list to store negotiation cipher options * @return byte[] SASL negotiation message * @throws IOException for any error */ public static byte[] readSaslMessageAndNegotiationCipherOptions( InputStream in, List<CipherOption> cipherOptions) throws IOException { DataTransferEncryptorMessageProto proto = DataTransferEncryptorMessageProto.parseFrom(vintPrefixed(in)); if (proto.getStatus() == DataTransferEncryptorStatus.ERROR_UNKNOWN_KEY) { throw new InvalidEncryptionKeyException(proto.getMessage()); } else if (proto.getStatus() == DataTransferEncryptorStatus.ERROR) { throw new IOException(proto.getMessage()); } else { List<CipherOptionProto> optionProtos = proto.getCipherOptionList(); if (optionProtos != null) { for (CipherOptionProto optionProto : optionProtos) { cipherOptions.add(PBHelperClient.convert(optionProto)); } } return proto.getPayload().toByteArray(); } }
public static List<CipherOptionProto> convertCipherOptions( List<CipherOption> options) { if (options != null) { List<CipherOptionProto> protos = Lists.newArrayListWithCapacity(options.size()); for (CipherOption option : options) { protos.add(convert(option)); } return protos; } return null; }
public static List<CipherOption> convertCipherOptionProtos( List<CipherOptionProto> protos) { if (protos != null) { List<CipherOption> options = Lists.newArrayListWithCapacity(protos.size()); for (CipherOptionProto proto : protos) { options.add(convert(proto)); } return options; } return null; }
List<CipherOptionProto> convertCipherOptions(List<CipherOption> options);
List<CipherOption> convertCipherOptionProtos(List<CipherOptionProto> options);