예제 #1
0
 @Override
 void rdataFromString(Tokenizer st, Name origin) throws IOException {
   String addr = st.getString();
   address = checkAndConvertAddress(addr);
   if (address == null) {
     throw st.exception("invalid NSAP address " + addr);
   }
 }
예제 #2
0
 Record rdataFromString(Name name, int dclass, long ttl, Tokenizer st, Name origin)
     throws IOException {
   CERTRecord rec = new CERTRecord(name, dclass, ttl);
   rec.certType = st.getUInt16();
   rec.keyTag = st.getUInt16();
   rec.alg = st.getUInt8();
   rec.cert = base64.fromString(remainingStrings(st));
   return rec;
 }
예제 #3
0
파일: LOCRecord.java 프로젝트: uppaljs/sef
  private long parsePosition(Tokenizer st, String type) throws IOException {
    boolean isLatitude = type.equals("latitude");
    int deg = 0, min = 0;
    double sec = 0;
    long value;
    String s;

    deg = st.getUInt16();
    if (deg > 180 || (deg > 90 && isLatitude))
      throw st.exception("Invalid LOC " + type + " degrees");

    s = st.getString();
    try {
      min = Integer.parseInt(s);
      if (min < 0 || min > 59) throw st.exception("Invalid LOC " + type + " minutes");
      s = st.getString();
      sec = parseFixedPoint(s);
      if (sec < 0 || sec >= 60) throw st.exception("Invalid LOC " + type + " seconds");
      s = st.getString();
    } catch (NumberFormatException e) {
    }

    if (s.length() != 1) throw st.exception("Invalid LOC " + type);

    value = (long) (1000 * (sec + 60L * (min + 60L * deg)));

    char c = Character.toUpperCase(s.charAt(0));
    if ((isLatitude && c == 'S') || (!isLatitude && c == 'W')) value = -value;
    else if ((isLatitude && c != 'N') || (!isLatitude && c != 'E'))
      throw st.exception("Invalid LOC " + type);

    value += (1L << 31);

    return value;
  }
예제 #4
0
  /**
   * Builds a new Record from its textual representation
   *
   * @param name The owner name of the record.
   * @param type The record's type.
   * @param dclass The record's class.
   * @param ttl The record's time to live.
   * @param st A tokenizer containing the textual representation of the rdata.
   * @param origin The default origin to be appended to relative domain names.
   * @return The new record
   * @throws IOException The text format was invalid.
   */
  public static Record fromString(
      Name name, int type, int dclass, long ttl, Tokenizer st, Name origin) throws IOException {
    Record rec;

    if (!name.isAbsolute()) throw new RelativeNameException(name);
    Type.check(type);
    DClass.check(dclass);
    TTL.check(ttl);

    Tokenizer.Token t = st.get();
    if (t.type == Tokenizer.IDENTIFIER && t.value.equals("\\#")) {
      int length = st.getUInt16();
      byte[] data = st.getHex();
      if (data == null) {
        data = new byte[0];
      }
      if (length != data.length)
        throw st.exception("invalid unknown RR encoding: " + "length mismatch");
      DNSInput in = new DNSInput(data);
      return newRecord(name, type, dclass, ttl, length, in);
    }
    st.unget();
    rec = getEmptyRecord(name, type, dclass, ttl, true);
    rec.rdataFromString(st, origin);
    t = st.get();
    if (t.type != Tokenizer.EOL && t.type != Tokenizer.EOF) {
      throw st.exception("unexpected tokens at end of record");
    }
    return rec;
  }
예제 #5
0
파일: LOCRecord.java 프로젝트: uppaljs/sef
 private long parseDouble(
     Tokenizer st, String type, boolean required, long min, long max, long defaultValue)
     throws IOException {
   Tokenizer.Token token = st.get();
   if (token.isEOL()) {
     if (required) throw st.exception("Invalid LOC " + type);
     st.unget();
     return defaultValue;
   }
   String s = token.value;
   if (s.length() > 1 && s.charAt(s.length() - 1) == 'm') s = s.substring(0, s.length() - 1);
   try {
     long value = (long) (100 * parseFixedPoint(s));
     if (value < min || value > max) throw st.exception("Invalid LOC " + type);
     return value;
   } catch (NumberFormatException e) {
     throw st.exception("Invalid LOC " + type);
   }
 }
예제 #6
0
 void rdataFromString(Tokenizer st, Name origin) throws IOException {
   host = st.getName(origin);
   admin = st.getName(origin);
   serial = st.getUInt32();
   refresh = st.getTTLLike();
   retry = st.getTTLLike();
   expire = st.getTTLLike();
   minimum = st.getTTLLike();
 }
예제 #7
0
 void rdataFromString(Tokenizer st, Name origin) throws IOException {
   order = st.getUInt16();
   preference = st.getUInt16();
   try {
     flags = byteArrayFromString(st.getString());
     service = byteArrayFromString(st.getString());
     regexp = byteArrayFromString(st.getString());
   } catch (TextParseException e) {
     throw st.exception(e.getMessage());
   }
   replacement = st.getName(origin);
 }
예제 #8
0
 void rdataFromString(Tokenizer st, Name origin) throws IOException {
   String certTypeString = st.getString();
   certType = CertificateType.value(certTypeString);
   if (certType < 0) throw st.exception("Invalid certificate type: " + certTypeString);
   keyTag = st.getUInt16();
   String algString = st.getString();
   alg = DNSSEC.Algorithm.value(algString);
   if (alg < 0) throw st.exception("Invalid algorithm: " + algString);
   cert = st.getBase64();
 }
예제 #9
0
 void rdataFromString(Tokenizer st, Name origin) throws IOException {
   String flagString = st.getIdentifier();
   flags = Flags.value(flagString);
   if (flags < 0) throw st.exception("Invalid flags: " + flagString);
   String protoString = st.getIdentifier();
   proto = Protocol.value(protoString);
   if (proto < 0) throw st.exception("Invalid protocol: " + protoString);
   String algString = st.getIdentifier();
   alg = DNSSEC.Algorithm.value(algString);
   if (alg < 0) throw st.exception("Invalid algorithm: " + algString);
   /* If this is a null KEY, there's no key data */
   if ((flags & Flags.USE_MASK) == Flags.NOKEY) key = null;
   else key = st.getBase64();
 }
예제 #10
0
 void rdataFromString(Tokenizer st, Name origin) throws IOException {
   throw st.exception("no text format defined for OPT");
 }
예제 #11
0
 void rdataFromString(Tokenizer st, Name origin) throws IOException {
   InetAddress address = st.getAddress(Address.IPv4);
   addr = fromArray(address.getAddress());
 }
예제 #12
0
 void rdataFromString(Tokenizer st, Name origin) throws IOException {
   address = st.getAddressBytes(Address.IPv6);
 }
예제 #13
0
 void rdataFromString(Tokenizer st, Name origin) throws IOException {
   throw st.exception("invalid unknown RR encoding");
 }
예제 #14
0
파일: SIGBase.java 프로젝트: lemmy/dnsjava
 protected static Record rdataFromString(SIGBase rec, Tokenizer st, Name origin)
     throws IOException {
   String typeString = st.getString();
   int covered = Type.value(typeString);
   if (covered < 0) throw st.exception("Invalid type: " + typeString);
   rec.covered = covered;
   String algString = st.getString();
   int alg = DNSSEC.Algorithm.value(algString);
   if (alg < 0) throw st.exception("Invalid algorithm: " + algString);
   rec.alg = alg;
   rec.labels = st.getUInt8();
   rec.origttl = st.getTTL();
   rec.expire = FormattedTime.parse(st.getString());
   rec.timeSigned = FormattedTime.parse(st.getString());
   rec.footprint = st.getUInt16();
   rec.signer = st.getName(origin);
   rec.signature = st.getBase64();
   return rec;
 }