static char authz_validate(const unsigned char *authz, size_t length)
	{
	unsigned char types_seen_bitmap[32];

	if (!authz)
		return 1;

	memset(types_seen_bitmap, 0, sizeof(types_seen_bitmap));

	for (;;)
		{
		unsigned char type, byte, bit;
		unsigned short len;

		if (!length)
			return 1;

		type = *(authz++);
		length--;

		byte = type / 8;
		bit = type & 7;
		if (types_seen_bitmap[byte] & (1 << bit))
			return 0;
		types_seen_bitmap[byte] |= (1 << bit);

		if (length < 2)
			return 0;
		len = ((unsigned short) authz[0]) << 8 |
		      ((unsigned short) authz[1]);
		authz += 2;
		length -= 2;

		if (length < len)
			return 0;

		authz += len;
		length -= len;
		}
	}