def METHOD_NAME(s: BinaryIO, tag: Tag) -> int:
    """
    Unpack an application tag and return the length of the application packet.
    :param s: stream
    :param tag: application tag.
    """
    byte = Uint8.unpack(s.read(1))
    if tag > 30:
        if byte != ((Class.BER_CLASS_APPL | PC.BER_CONSTRUCT) | Tag.BER_TAG_MASK):
            raise ValueError("Invalid BER tag")
        byte = Uint8.unpack(s.read(1))
        if byte != tag:
            raise ValueError("Unexpected application tag")
    else:
        if byte != ((Class.BER_CLASS_APPL | PC.BER_CONSTRUCT) | (tag & Tag.BER_TAG_MASK)):
            raise ValueError("Unexpected application tag")
    return readLength(s)