+#include "onak.h"
+#include "openpgp.h"
+
+/*
+ * Convert a Public Key algorithm to its single character representation.
+ */
+char pkalgo2char(uint8_t algo)
+{
+ char typech;
+
+ switch (algo) {
+ case OPENPGP_PKALGO_DSA:
+ typech = 'D';
+ break;
+ case OPENPGP_PKALGO_ECDSA:
+ case OPENPGP_PKALGO_EDDSA:
+ typech = 'E';
+ break;
+ case OPENPGP_PKALGO_EC:
+ typech = 'e';
+ break;
+ case OPENPGP_PKALGO_ELGAMAL_SIGN:
+ typech = 'G';
+ break;
+ case OPENPGP_PKALGO_ELGAMAL_ENC:
+ typech = 'g';
+ break;
+ case OPENPGP_PKALGO_RSA:
+ typech = 'R';
+ break;
+ case OPENPGP_PKALGO_RSA_ENC:
+ typech = 'r';
+ break;
+ case OPENPGP_PKALGO_RSA_SIGN:
+ typech = 's';
+ break;
+ default:
+ typech = '?';
+ break;
+ }
+
+ return typech;
+}
+
+/**
+ * html_escape - Takes a string and converts it to HTML.
+ * @src: The string to HTMLize.
+ * @src_len: The length of the source string
+ * @dst: A buffer to put the escaped string into
+ * @dst_len: Length of the destination buffer (including a trailing NULL)
+ *
+ * Takes a string and escapes any HTML entities (<, >, &, ", '). Returns
+ * dst.
+ */
+const char *html_escape(const char *src, size_t src_len,
+ char *dst, size_t dst_len)
+{
+ size_t in_pos, out_pos;
+
+ dst_len--;
+
+ for (in_pos = 0, out_pos = 0;
+ in_pos < src_len && out_pos < (dst_len - 1);
+ in_pos++, out_pos++) {
+ switch (src[in_pos]) {
+ case '<':
+ if ((out_pos + 4) >= dst_len) {
+ break;
+ }
+ dst[out_pos++] = '&';
+ dst[out_pos++] = 'l';
+ dst[out_pos++] = 't';
+ dst[out_pos] = ';';
+ break;
+ case '>':
+ if ((out_pos + 4) >= dst_len) {
+ break;
+ }
+ dst[out_pos++] = '&';
+ dst[out_pos++] = 'g';
+ dst[out_pos++] = 't';
+ dst[out_pos] = ';';
+ break;
+ case '"':
+ if ((out_pos + 6) >= dst_len) {
+ break;
+ }
+ dst[out_pos++] = '&';
+ dst[out_pos++] = 'q';
+ dst[out_pos++] = 'u';
+ dst[out_pos++] = 'o';
+ dst[out_pos++] = 't';
+ dst[out_pos] = ';';
+ break;
+ case '\'':
+ if ((out_pos + 5) >= dst_len) {
+ break;
+ }
+ dst[out_pos++] = '&';
+ dst[out_pos++] = '#';
+ dst[out_pos++] = '3';
+ dst[out_pos++] = '9';
+ dst[out_pos] = ';';
+ break;
+ case '&':
+ if ((out_pos + 5) >= dst_len) {
+ break;
+ }
+ dst[out_pos++] = '&';
+ dst[out_pos++] = 'a';
+ dst[out_pos++] = 'm';
+ dst[out_pos++] = 'p';
+ dst[out_pos] = ';';
+ break;
+ default:
+ dst[out_pos] = src[in_pos];
+ }
+ }
+ dst[out_pos] = 0;