/*
 * ABOUTME: Hex-encoding helper for rdata presentation rendering.
 * ABOUTME: encode_hex_temp() returns temp-pool lowercase hex, like encode_base64_temp.
 *
 * Part of DNS zone file validator `validns`.
 *
 * Copyright 2025-2026 OARC, Inc.
 * Copyright 2011-2025 Anton Berezin <tobez@tobez.org>
 * Modified BSD license.
 * (See LICENSE file in the distribution.)
 *
 */
#ifndef _HEX_H_
#define _HEX_H_ 1

#include "mempool.h"

static inline char* encode_hex_temp(const unsigned char* src, int n)
{
    static const char hex[] = "0123456789abcdef";
    char*             out   = getmem_temp(2 * n + 1);
    int               i;

    for (i = 0; i < n; i++) {
        out[2 * i]     = hex[(src[i] >> 4) & 0x0f];
        out[2 * i + 1] = hex[src[i] & 0x0f];
    }
    out[2 * n] = '\0';
    return out;
}

#endif
