anastasis

Credential backup and recovery protocol and service
Log | Files | Refs | Submodules | README | LICENSE

anastasis-cli-common.h (1906B)


      1 /*
      2   This file is part of Anastasis
      3   Copyright (C) 2026 Anastasis SARL
      4 
      5   Anastasis is free software; you can redistribute it and/or modify it under the
      6   terms of the GNU Lesser General Public License as published by the Free Software
      7   Foundation; either version 3, or (at your option) any later version.
      8 
      9   Anastasis is distributed in the hope that it will be useful, but WITHOUT ANY
     10   WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
     11   A PARTICULAR PURPOSE.  See the GNU Affero General Public License for more details.
     12 
     13   You should have received a copy of the GNU Affero General Public License along with
     14   Anastasis; see the file COPYING.GPL.  If not, see <http://www.gnu.org/licenses/>
     15 */
     16 /**
     17  * @file cli/anastasis-cli-common.h
     18  * @brief helpers shared by the Anastasis command line tools
     19  * @author Christian Grothoff
     20  */
     21 #ifndef ANASTASIS_CLI_COMMON_H
     22 #define ANASTASIS_CLI_COMMON_H
     23 
     24 #include <jansson.h>
     25 #include <stdio.h>
     26 
     27 
     28 /**
     29  * Largest reducer state we are willing to read from a stream.  Matches the
     30  * 16 MB upload limit the provider backend applies to recovery documents, so
     31  * anything bigger could not have come from (or be sent to) a provider anyway.
     32  */
     33 #define ANASTASIS_CLI_MAX_STATE_SIZE (16 * 1024 * 1024)
     34 
     35 
     36 /**
     37  * Read a JSON value from @a f, refusing inputs larger than
     38  * #ANASTASIS_CLI_MAX_STATE_SIZE.  Unlike json_loadf(), this cannot be made to
     39  * consume unbounded memory by a caller that keeps writing to our stdin.  If
     40  * @a f is a regular file we simply map it and check st_size against the limit;
     41  * otherwise the limit bounds how much we read from the stream.
     42  *
     43  * @param f stream to read from, read until EOF
     44  * @param[out] error set to the parse (or size) error on failure
     45  * @return the parsed JSON, or NULL on error
     46  */
     47 json_t *
     48 ANASTASIS_CLI_json_load_capped (FILE *f,
     49                                 json_error_t *error);
     50 
     51 
     52 #endif