Project homepage Mailing List  Warmcat.com  API Docs  Github Mirror 
{"schema":"libjg2-1", "vpath":"/git/", "avatar":"/git/avatar/", "alang":"en-US,en;q\u003d0.5", "gen_ut":1702155411, "reponame":"libwebsockets", "desc":"libwebsockets lightweight C networking library", "owner": { "name": "Andy Green", "email": "andy@warmcat.com", "md5": "c50933ca2aa61e0fe2c43d46bb6b59cb" },"url":"https://libwebsockets.org/repo/libwebsockets", "f":3, "items": [ {"schema":"libjg2-1", "cid":"3b961883a940a64858cdc975b1ad3e90", "oid":{ "oid": "cfa9d88e073533f7505853b6ed9e34ee80d8310f", "alias": [ "refs/heads/main"]},"blobname": "include/libwebsockets/lws-jwk.h", "blob": "/*\n * libwebsockets - small server side websockets and web server implementation\n *\n * Copyright (C) 2010 - 2019 Andy Green \u003candy@warmcat.com\u003e\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \u0022Software\u0022), to\n * deal in the Software without restriction, including without limitation the\n * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or\n * sell copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in\n * all copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \u0022AS IS\u0022, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING\n * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS\n * IN THE SOFTWARE.\n */\n\n/*! \u005cdefgroup jwk JSON Web Keys\n * ## JSON Web Keys API\n *\n * Lws provides an API to parse JSON Web Keys into a struct lws_gencrypto_keyelem.\n *\n * \u0022oct\u0022 and \u0022RSA\u0022 type keys are supported. For \u0022oct\u0022 keys, they are held in\n * the \u0022e\u0022 member of the struct lws_gencrypto_keyelem.\n *\n * Keys elements are allocated on the heap. You must destroy the allocations\n * in the struct lws_gencrypto_keyelem by calling\n * lws_genrsa_destroy_elements() when you are finished with it.\n */\n///@{\n\nenum enum_jwk_meta_tok {\n\tJWK_META_KTY,\n\tJWK_META_KID,\n\tJWK_META_USE,\n\tJWK_META_KEY_OPS,\n\tJWK_META_X5C,\n\tJWK_META_ALG,\n\n\tLWS_COUNT_JWK_ELEMENTS\n};\n\nstruct lws_jwk {\n\t/* key data elements */\n\tstruct lws_gencrypto_keyelem e[LWS_GENCRYPTO_MAX_KEYEL_COUNT];\n\t/* generic meta key elements, like KID */\n\tstruct lws_gencrypto_keyelem meta[LWS_COUNT_JWK_ELEMENTS];\n\tint kty;\t\t\t/**\u003c one of LWS_GENCRYPTO_KTY_ */\n\tchar private_key; /* nonzero \u003d has private key elements */\n};\n\ntypedef int (*lws_jwk_key_import_callback)(struct lws_jwk *s, void *user);\n\nstruct lws_jwk_parse_state {\n\tstruct lws_jwk *jwk;\n\tchar b64[(((8192 / 8) * 4) / 3) + 1]; /* enough for 8Kb key */\n\tlws_jwk_key_import_callback per_key_cb;\n\tvoid *user;\n\tint pos;\n\tint cose_state;\n\tint seen;\n\tunsigned short possible;\n};\n\n/** lws_jwk_import() - Create a JSON Web key from the textual representation\n *\n * \u005cparam jwk: the JWK object to create\n * \u005cparam cb: callback for each jwk-processed key, or NULL if importing a single\n *\t key with no parent \u0022keys\u0022 JSON\n * \u005cparam user: pointer to be passed to the callback, otherwise ignored by lws.\n *\t\tNULL if importing a single key with no parent \u0022keys\u0022 JSON\n * \u005cparam in: a single JWK JSON stanza in utf-8\n * \u005cparam len: the length of the JWK JSON stanza in bytes\n *\n * Creates an lws_jwk struct filled with data from the JSON representation.\n *\n * There are two ways to use this... with some protocols a single jwk is\n * delivered with no parent \u0022keys\u0022: [] array. If you call this with cb and\n * user as NULL, then the input will be interpreted like that and the results\n * placed in s.\n *\n * The second case is that you are dealing with a \u0022keys\u0022:[] array with one or\n * more keys in it. In this case, the function iterates through the keys using\n * s as a temporary jwk, and calls the user-provided callback for each key in\n * turn while it return 0 (nonzero return from the callback terminates the\n * iteration through any further keys).\n */\nLWS_VISIBLE LWS_EXTERN int\nlws_jwk_import(struct lws_jwk *jwk, lws_jwk_key_import_callback cb, void *user,\n\t const char *in, size_t len);\n\n/** lws_jwk_destroy() - Destroy a JSON Web key\n *\n * \u005cparam jwk: the JWK object to destroy\n *\n * All allocations in the lws_jwk are destroyed\n */\nLWS_VISIBLE LWS_EXTERN void\nlws_jwk_destroy(struct lws_jwk *jwk);\n\n/** lws_jwk_dup_oct() - Set a jwk to a dup'd binary OCT key\n *\n * \u005cparam jwk: the JWK object to set\n * \u005cparam key: the JWK object to destroy\n * \u005cparam len: the JWK object to destroy\n *\n * Sets the kty to OCT, allocates len bytes for K and copies len bytes of key\n * into the allocation.\n */\nLWS_VISIBLE LWS_EXTERN int\nlws_jwk_dup_oct(struct lws_jwk *jwk, const void *key, int len);\n\n#define LWSJWKF_EXPORT_PRIVATE\t\t\t\t(1 \u003c\u003c 0)\n#define LWSJWKF_EXPORT_NOCRLF\t\t\t\t(1 \u003c\u003c 1)\n\n/** lws_jwk_export() - Export a JSON Web key to a textual representation\n *\n * \u005cparam jwk: the JWK object to export\n * \u005cparam flags: control export options\n * \u005cparam p: the buffer to write the exported JWK to\n * \u005cparam len: the length of the buffer \u005cp p in bytes... reduced by used amount\n *\n * Returns length of the used part of the buffer if OK, or -1 for error.\n *\n * \u005cp flags can be OR-ed together\n *\n * LWSJWKF_EXPORT_PRIVATE: default is only public part, set this to also export\n *\t\t\t the private part\n *\n * LWSJWKF_EXPORT_NOCRLF: normally adds a CRLF at the end of the export, if\n *\t\t\t you need to suppress it, set this flag\n *\n * Serializes the content of the JWK into a char buffer.\n */\nLWS_VISIBLE LWS_EXTERN int\nlws_jwk_export(struct lws_jwk *jwk, int flags, char *p, int *len);\n\n/** lws_jwk_load() - Import a JSON Web key from a file\n *\n * \u005cparam jwk: the JWK object to load into\n * \u005cparam filename: filename to load from\n * \u005cparam cb: optional callback for each key\n * \u005cparam user: opaque user pointer passed to cb if given\n *\n * Returns 0 for OK or -1 for failure\n *\n * There are two ways to use this... with some protocols a single jwk is\n * delivered with no parent \u0022keys\u0022: [] array. If you call this with cb and\n * user as NULL, then the input will be interpreted like that and the results\n * placed in s.\n *\n * The second case is that you are dealing with a \u0022keys\u0022:[] array with one or\n * more keys in it. In this case, the function iterates through the keys using\n * s as a temporary jwk, and calls the user-provided callback for each key in\n * turn while it return 0 (nonzero return from the callback terminates the\n * iteration through any further keys, leaving the last one in s).\n */\nLWS_VISIBLE LWS_EXTERN int\nlws_jwk_load(struct lws_jwk *jwk, const char *filename,\n\t lws_jwk_key_import_callback cb, void *user);\n\n/** lws_jwk_save() - Export a JSON Web key to a file\n *\n * \u005cparam jwk: the JWK object to save from\n * \u005cparam filename: filename to save to\n *\n * Returns 0 for OK or -1 for failure\n */\nLWS_VISIBLE LWS_EXTERN int\nlws_jwk_save(struct lws_jwk *jwk, const char *filename);\n\n/** lws_jwk_rfc7638_fingerprint() - jwk to RFC7638 compliant fingerprint\n *\n * \u005cparam jwk: the JWK object to fingerprint\n * \u005cparam digest32: buffer to take 32-byte digest\n *\n * Returns 0 for OK or -1 for failure\n */\nLWS_VISIBLE LWS_EXTERN int\nlws_jwk_rfc7638_fingerprint(struct lws_jwk *jwk, char *digest32);\n\n/** lws_jwk_strdup_meta() - allocate a duplicated string meta element\n *\n * \u005cparam jwk: the JWK object to fingerprint\n * \u005cparam idx: JWK_META_ element index\n * \u005cparam in: string to copy\n * \u005cparam len: length of string to copy\n *\n * Returns 0 for OK or nonzero for failure\n */\nLWS_VISIBLE LWS_EXTERN int\nlws_jwk_strdup_meta(struct lws_jwk *jwk, enum enum_jwk_meta_tok idx,\n\t\t const char *in, int len);\n\n\nLWS_VISIBLE LWS_EXTERN int\nlws_jwk_dump(struct lws_jwk *jwk);\n\n/** lws_jwk_generate() - create a new key of given type and characteristics\n *\n * \u005cparam context: the struct lws_context used for RNG\n * \u005cparam jwk: the JWK object to fingerprint\n * \u005cparam kty: One of the LWS_GENCRYPTO_KTY_ key types\n * \u005cparam bits: for OCT and RSA keys, the number of bits\n * \u005cparam curve: for EC keys, the name of the curve\n *\n * Returns 0 for OK or nonzero for failure\n */\nLWS_VISIBLE int\nlws_jwk_generate(struct lws_context *context, struct lws_jwk *jwk,\n\t enum lws_gencrypto_kty kty, int bits, const char *curve);\n\n///@}\n","s":{"c":1702112693,"u": 551}} ],"g": 2007,"chitpc": 0,"ehitpc": 0,"indexed":0 , "ab": 0, "si": 0, "db":0, "di":0, "sat":0, "lfc": "7d0a"}