}
static void *
-rspamd_cryptobox_pubkey_pk (struct rspamd_cryptobox_pubkey *kp,
+rspamd_cryptobox_pubkey_pk (const struct rspamd_cryptobox_pubkey *kp,
guint *len)
{
g_assert (kp != NULL);
return TRUE;
}
+
+gboolean
+rspamd_pubkey_equal (const struct rspamd_cryptobox_pubkey *k1,
+ const struct rspamd_cryptobox_pubkey *k2)
+{
+ guchar *p1 = NULL, *p2 = NULL;
+ guint len1, len2;
+
+
+ if (k1->alg == k2->alg && k1->type == k2->type) {
+ p1 = rspamd_cryptobox_pubkey_pk (k1, &len1);
+ p2 = rspamd_cryptobox_pubkey_pk (k2, &len2);
+
+ if (len1 == len2) {
+ return (memcmp (p1, p2, len1) == 0);
+ }
+ }
+
+ return FALSE;
+}
const void *data, gsize len, guchar *sig, gsize siglen,
GError **err);
+/**
+ * Compares two public keys
+ * @param k1 key to compare
+ * @param k2 key to compare
+ * @return TRUE if two keys are equal
+ */
+gboolean rspamd_pubkey_equal (const struct rspamd_cryptobox_pubkey *k1,
+ const struct rspamd_cryptobox_pubkey *k2);
+
#endif /* SRC_LIBCRYPTOBOX_KEYPAIR_H_ */
priv->local_key = rspamd_keypair_ref (key);
}
+const struct rspamd_cryptobox_pubkey*
+rspamd_http_connection_get_peer_key (struct rspamd_http_connection *conn)
+{
+ struct rspamd_http_connection_private *priv = conn->priv;
+
+ if (priv->peer_key) {
+ return priv->peer_key;
+ }
+ else if (priv->msg) {
+ return priv->msg->peer_key;
+ }
+
+ return NULL;
+}
+
gboolean
rspamd_http_connection_is_encrypted (struct rspamd_http_connection *conn)
{
void rspamd_http_connection_set_key (struct rspamd_http_connection *conn,
struct rspamd_cryptobox_keypair *key);
+/**
+ * Get peer's public key
+ * @param conn connection structure
+ * @return pubkey structure or NULL
+ */
+const struct rspamd_cryptobox_pubkey* rspamd_http_connection_get_peer_key (
+ struct rspamd_http_connection *conn);
+
/**
* Returns TRUE if a connection is encrypted
* @param conn