@@ -87,8 +87,7 @@ static bool ensure_hsm_secret_exists(int fd, const char *path)
8787/* Load hsm_secret using the unified interface */
8888static struct hsm_secret * load_hsm_secret (const tal_t * ctx , const char * hsm_secret_path )
8989{
90- size_t contents_len ;
91- u8 * contents = grab_file_contents (tmpctx , hsm_secret_path , & contents_len );
90+ u8 * contents = grab_file_raw (tmpctx , hsm_secret_path );
9291 const char * passphrase = NULL ;
9392 struct hsm_secret * hsms ;
9493 enum hsm_secret_error error ;
@@ -97,15 +96,15 @@ static struct hsm_secret *load_hsm_secret(const tal_t *ctx, const char *hsm_secr
9796 err (EXITCODE_ERROR_HSM_FILE , "Reading hsm_secret" );
9897
9998 /* Get passphrase if needed */
100- if (hsm_secret_needs_passphrase (contents , contents_len )) {
99+ if (hsm_secret_needs_passphrase (contents , tal_bytelen ( contents ) )) {
101100 printf ("Enter hsm_secret password:\n" );
102101 fflush (stdout );
103102 passphrase = read_stdin_pass (tmpctx , & error );
104103 if (!passphrase )
105104 errx (EXITCODE_ERROR_HSM_FILE , "Could not read password: %s" , hsm_secret_error_str (error ));
106105 }
107106
108- hsms = extract_hsm_secret (ctx , contents , contents_len , passphrase , & error );
107+ hsms = extract_hsm_secret (ctx , contents , tal_bytelen ( contents ) , passphrase , & error );
109108 if (!hsms ) {
110109 err (EXITCODE_ERROR_HSM_FILE , "%s" , hsm_secret_error_str (error ));
111110 }
@@ -120,12 +119,11 @@ static void decrypt_hsm(const char *hsm_secret_path)
120119 const char * dir , * backup ;
121120
122121 /* Check if it's a format we can decrypt */
123- size_t contents_len ;
124- u8 * contents = grab_file_contents (tmpctx , hsm_secret_path , & contents_len );
122+ u8 * contents = grab_file_raw (tmpctx , hsm_secret_path );
125123 if (!contents )
126124 err (EXITCODE_ERROR_HSM_FILE , "Reading hsm_secret" );
127125
128- enum hsm_secret_type type = detect_hsm_secret_type (contents , contents_len );
126+ enum hsm_secret_type type = detect_hsm_secret_type (contents , tal_bytelen ( contents ) );
129127
130128 if (type != HSM_SECRET_ENCRYPTED ) {
131129 errx (ERROR_USAGE , "decrypt command only works on legacy encrypted binary format (73 bytes).\n"
@@ -178,12 +176,11 @@ static void encrypt_hsm(const char *hsm_secret_path)
178176 enum hsm_secret_error pass_err ;
179177
180178 /* Check if it's a format we can encrypt */
181- size_t contents_len ;
182- u8 * contents = grab_file_contents (tmpctx , hsm_secret_path , & contents_len );
179+ u8 * contents = grab_file_raw (tmpctx , hsm_secret_path );
183180 if (!contents )
184181 err (EXITCODE_ERROR_HSM_FILE , "Reading hsm_secret" );
185182
186- enum hsm_secret_type type = detect_hsm_secret_type (contents , contents_len );
183+ enum hsm_secret_type type = detect_hsm_secret_type (contents , tal_bytelen ( contents ) );
187184
188185 if (type != HSM_SECRET_PLAIN ) {
189186 errx (ERROR_USAGE , "encrypt command only works on legacy plain binary format (32 bytes).\n"
@@ -290,15 +287,14 @@ static void print_codexsecret(const char *hsm_secret_path, const char *id)
290287
291288static void print_emergencyrecover (const char * emer_rec_path )
292289{
293- size_t scb_len ;
294- u8 * scb = grab_file_contents (tmpctx , emer_rec_path , & scb_len );
290+ u8 * scb = grab_file_raw (tmpctx , emer_rec_path );
295291 char * output , * hrp = "clnemerg" ;
296292 if (!scb ) {
297293 err (EXITCODE_ERROR_HSM_FILE , "Reading emergency.recover" );
298294 }
299295 u5 * data = tal_arr (tmpctx , u5 , 0 );
300296
301- bech32_push_bits (& data , scb , scb_len * 8 );
297+ bech32_push_bits (& data , scb , tal_bytelen ( scb ) * 8 );
302298 output = tal_arr (tmpctx , char , strlen (hrp ) + tal_count (data ) + 8 );
303299
304300 bech32_encode (output , hrp , data , tal_count (data ), (size_t )-1 ,
0 commit comments