code: public static AlgorithmId parse(DerValue val) throws IOException {
          if (val.tag != DerValue.tag_Sequence) {
              throw new IOException("algid parse error, not a sequence");
          }
  
          /*
           * Get the algorithm ID and any parameters.
           */
          ObjectIdentifier        algid;
          DerValue                params;
          DerInputStream          in = val.toDerInputStream();
  
          algid = in.getOID();
          if (in.available() == 0) {
              params = null;
          } else {
              params = in.getDerValue();
              if (params.tag == DerValue.tag_Null) {
                  if (params.length() != 0) {
                      throw new IOException("invalid NULL");
                  }
                  params = null;
              }
              if (in.available() != 0) {
                  throw new IOException("Invalid AlgorithmIdentifier: extra data");
              }
          }
  
          return new AlgorithmId(algid, params);
      }
docs: Parse (unmarshal) an ID from a DER sequence input value.  This form
  parsing might be used when expanding a value which has already been
  partially unmarshaled as a set or sequence member.
  
  @exception IOException on error.
  @param val the input value, which contains the algid and, if
  there are any parameters, those parameters.
  @return an ID for the algorithm.  If the system is configured
  appropriately, this may be an instance of a class
  with some kind of special support for this algorithm.
  In that case, you may "narrow" the type of the ID.