From 1489963b5817f97760ce6cd8a177ddb75fd30f44 Mon Sep 17 00:00:00 2001 From: Volker Birk Date: Fri, 8 Feb 2019 21:51:42 +0100 Subject: [PATCH] more sample code for Nana ;-) --- .hgignore | 1 + api/Makefile | 9 ++-- api/basic_api.yml2 | 4 ++ api/message_api.yml2 | 98 ++++++++++++++++++-------------------------- api/pEp.yml2 | 20 +++++++++ 5 files changed, 72 insertions(+), 60 deletions(-) diff --git a/.hgignore b/.hgignore index 3b33df7c..59fd1f8f 100644 --- a/.hgignore +++ b/.hgignore @@ -77,4 +77,5 @@ sync/.codegen sync/.statemachines test/msg_2.0.asc test/*Tests +api/*.h diff --git a/api/Makefile b/api/Makefile index 79fb4b88..6196d3e0 100644 --- a/api/Makefile +++ b/api/Makefile @@ -1,12 +1,15 @@ -all: basic_api.h +all: pEp.xml basic_api.h -%.xml: %.yml2 +YML2=$(wildcard *.yml2) +YSL2=$(wildcard *.ysl2) + +%.xml: %.yml2 $(YML2) $(YSL2) yml2proc -P $< -o $@ %.xsl: %.ysl2 yml2proc -DP $< -o $@ -%.h: %.yml2 pEp.yml2 gen_c_header.ysl2 to_c.ysl2 +%.h: $(YML2) $(YSL2) yml2proc -y gen_c_header.ysl2 pEp.yml2 .PHONY: clean diff --git a/api/basic_api.yml2 b/api/basic_api.yml2 index db881078..cfd51d71 100644 --- a/api/basic_api.yml2 +++ b/api/basic_api.yml2 @@ -14,9 +14,13 @@ type hex extends string > a-f0-9 type hash doc="32bit Key ID to SHA512 in hex" extends hex min=16, max=128; +type hash_list doc="sequence of fingerprints of keys" + extends list< hash >; + type TID doc="UUID version 4 variant 1" extends binary size=16; + enum comm_type { hex unknown 0; diff --git a/api/message_api.yml2 b/api/message_api.yml2 index 9ce42dc6..feb6d57f 100644 --- a/api/message_api.yml2 +++ b/api/message_api.yml2 @@ -7,62 +7,46 @@ // written by Volker Birk -/* - struct message { -typedef enum _PEP_text_format { - PEP_text_format_plain = 0, - PEP_text_format_html, - PEP_text_format_other = 0xff -} PEP_text_format; - -typedef enum _PEP_msg_direction { - PEP_dir_incoming = 0, - PEP_dir_outgoing -} PEP_msg_direction; - -typedef enum _PEP_enc_format { - PEP_enc_none = 0, // message is not encrypted - PEP_enc_pieces, // inline PGP + PGP extensions - PEP_enc_S_MIME, // RFC5751 - PEP_enc_PGP_MIME, // RFC3156 - PEP_enc_PEP, // pEp encryption format - PEP_enc_PGP_MIME_Outlook1 // Message B0rken by Outlook type 1 -} PEP_enc_format; - -struct _message_ref_list; - -typedef struct _message { - PEP_msg_direction dir; - char *id; // UTF-8 string of message ID - char *shortmsg; // UTF-8 string of short message - char *longmsg; // UTF-8 string of long message - // (plain) - char *longmsg_formatted; // UTF-8 string of long message - // (formatted) - bloblist_t *attachments; // blobs with attachements - char *rawmsg_ref; // reference to raw message data - size_t rawmsg_size; // size of raw message data - timestamp *sent; // when the message is sent - timestamp *recv; // when the message is received - pEp_identity *from; // whom the message is from - identity_list *to; // whom the message is to - pEp_identity *recv_by; // via which identity the message - // is received - identity_list *cc; // whom a CC is being sent - identity_list *bcc; // whom a BCC is being sent - identity_list *reply_to; // where a reply should go to - stringlist_t *in_reply_to; // list of UTF-8 strings with - // MessageIDs of refering messages - struct _message *refering_msg_ref; // reference to refering message - stringlist_t *references; // list of UTF-8 strings with references - struct _message_ref_list *refered_by; // list of references to messages being - // refered - stringlist_t *keywords; // list of UTF-8 strings with keywords - char *comments; // UTF-8 string with comments - stringpair_list_t *opt_fields; // optional fields - PEP_enc_format enc_format; // format of encrypted data -} message; - +protocol session { + method encrypt_message + doc="encrypt message in memory" + { + // parms + + supply message src + doc=""" + message to encrypt - usually in-only, but can be in-out for + unencrypted messages; in that case, we may attach the key and + decorate the message + """; + + use hash_list extra doc="extra keys for encryption"; + + create message dst + doc=""" + pointer to new encrypted message or #NV if no encryption could + take place + """ + + use encformat format doc="encrypted format"; + + // flags + + flags { + flag default 0x0; + flag force_encryption 0x1; + } + + // exceptions + + throws key_has_ambig_name + doc="at least one of the receipient keys has an ambiguous name"; + + throws unencrypted + doc=""" + on demand or no recipients with usable key, is left unencrypted, + and key is attached to it + """ } -*/ +} diff --git a/api/pEp.yml2 b/api/pEp.yml2 index da0689f6..042c368e 100644 --- a/api/pEp.yml2 +++ b/api/pEp.yml2 @@ -17,6 +17,26 @@ decl struct @name; decl field @type @name; decl hex is item (output=hex); decl flag @name; +decl protocol @name; +decl method @name; + +// use: readonly in param, ownership remains with caller +decl use @type @name (mode=use) alias parm; + +// supply: inout param, ownership remains with caller +decl supply @type @name (mode=supply) alias parm; + +// create: factory delivers this, ownership goes to caller +decl create @type @name (mode=create) alias parm; + +// provide: in param, ownership goes to callee +decl provide @type @name (mode=provide) alias parm; + +// return: out param, ownership goes to callee +decl return @type @name (mode=return) alias parm; + +decl throws @except; +decl caveat(mode=caveat) alias doc; package pEp {