All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.xbill.DNS.DnssecAlgorithmOption Maven / Gradle / Ivy

There is a newer version: 3.6.2_1
Show newest version
// SPDX-License-Identifier: BSD-2-Clause
package org.xbill.DNS;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
import org.xbill.DNS.DNSSEC.Algorithm;

/**
 * The EDNS0 Option for Signaling Cryptographic Algorithm Understanding in DNS Security Extensions
 * (DNSSEC), RFC 6975.
 */
public class DnssecAlgorithmOption extends EDNSOption {
  private List algCodes;

  private DnssecAlgorithmOption(int code) {
    super(code);
    switch (code) {
      case Code.DAU:
      case Code.DHU:
      case Code.N3U:
        break;
      default:
        throw new IllegalArgumentException("Invalid option code, must be one of DAU, DHU, N3U");
    }
    algCodes = new ArrayList<>();
  }

  public DnssecAlgorithmOption(int code, List algCodes) {
    this(code);
    this.algCodes.addAll(algCodes);
  }

  public DnssecAlgorithmOption(int code, int... algCodes) {
    this(code);
    if (algCodes != null) {
      for (int algCode : algCodes) {
        this.algCodes.add(algCode);
      }
    }
  }

  public List getAlgorithms() {
    return Collections.unmodifiableList(algCodes);
  }

  @Override
  void optionFromWire(DNSInput in) throws IOException {
    algCodes.clear();
    while (in.remaining() > 0) {
      algCodes.add(in.readU8());
    }
  }

  @Override
  void optionToWire(DNSOutput out) {
    algCodes.forEach(out::writeU8);
  }

  @Override
  String optionToString() {
    return Code.string(getCode())
        + ": ["
        + algCodes.stream().map(Algorithm::string).collect(Collectors.joining(", "))
        + "]";
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy