def validate_spki
      unless @spki.is_a?(OpenSSL::ASN1::Sequence)
        raise SPKIError,
              "SPKI data is not an ASN1 sequence (got a #{@spki.class})"
      end

      if @spki.value.length != 2
        raise SPKIError,
              "SPKI top-level sequence must have two elements (length is #{@spki.value.length})"
      end

      alg_id, key_data = @spki.value

      unless alg_id.is_a?(OpenSSL::ASN1::Sequence)
        raise SPKIError,
              "SPKI algorithm_identifier must be a sequence (got a #{alg_id.class})"
      end

      unless (1..2) === alg_id.value.length
        raise SPKIError,
              "SPKI algorithm sequence must have one or two elements (got #{alg_id.value.length} elements)"
      end

      unless alg_id.value.first.is_a?(OpenSSL::ASN1::ObjectId)
        raise SPKIError,
              "SPKI algorithm identifier does not contain an object ID (got #{alg_id.value.first.class})"
      end

      unless key_data.is_a?(OpenSSL::ASN1::BitString)
        raise SPKIError,
              "SPKI publicKeyInfo field must be a BitString (got a #{@spki.value.last.class})"
      end
    end
def validate_spki
      unless @spki.is_a?(OpenSSL::ASN1::Sequence)
        raise SPKIError,
              "SPKI data is not an ASN1 sequence (got a #{@spki.class})"
      end

      if @spki.value.length != 2
        raise SPKIError,
              "SPKI top-level sequence must have two elements (length is #{@spki.value.length})"
      end

      alg_id, key_data = @spki.value

      unless alg_id.is_a?(OpenSSL::ASN1::Sequence)
        raise SPKIError,
              "SPKI algorithm_identifier must be a sequence (got a #{alg_id.class})"
      end

      unless (1..2) === alg_id.value.length
        raise SPKIError,
              "SPKI algorithm sequence must have one or two elements (got #{alg_id.value.length} elements)"
      end

      unless alg_id.value.first.is_a?(OpenSSL::ASN1::ObjectId)
        raise SPKIError,
              "SPKI algorithm identifier does not contain an object ID (got #{alg_id.value.first.class})"
      end

      unless key_data.is_a?(OpenSSL::ASN1::BitString)
        raise SPKIError,
              "SPKI publicKeyInfo field must be a BitString (got a #{@spki.value.last.class})"
      end
    end
Make sure that the SPKI data we were passed is legit.