detect.c (585B)
1 #include <stddef.h> 2 #include <string.h> 3 4 #include "common.h" 5 #include "armor.h" 6 7 #ifdef __cplusplus 8 extern "C" { 9 #endif 10 11 char fmt_asc_detect(unsigned char *cipherdata, size_t len) { 12 // Stream-friendly: either armor block may start on any line. 13 // Claiming is cheap; decode validates and returns NULL on garbage, 14 // letting readKeyFile move on to the next format. 15 if (asc_find_block(cipherdata, len, ASC_LABEL_PRIVATE, NULL, NULL)) return 1; 16 if (asc_find_block(cipherdata, len, ASC_LABEL_PUBLIC, NULL, NULL)) return 1; 17 return 0; 18 } 19 20 #ifdef __cplusplus 21 } // extern "C" 22 #endif