bool compare_text_files(const string& filename1, const string& filename2) { string contents1; if (!load_text_file(filename1, contents1)) return false; string contents2; if (!load_text_file(filename2, contents2)) return false; return contents1 == contents2; }
void web_page::on_document_loaded(LPCWSTR file, LPCWSTR encoding, LPCWSTR realUrl) { if (realUrl) { m_url = realUrl; } #ifdef LITEHTML_UTF8 litehtml::byte* html_text = load_utf8_file(file, true); if(!html_text) { LPCSTR txt = "<h1>Something Wrong</h1>"; html_text = new litehtml::byte[lstrlenA(txt) + 1]; lstrcpyA((LPSTR) html_text, txt); } m_doc = litehtml::document::createFromUTF8((const char*) html_text, this, m_parent->get_html_context()); delete html_text; #else LPWSTR html_text = load_text_file(file, true, encoding); if(!html_text) { LPCWSTR txt = L"<h1>Something Wrong</h1>"; html_text = new WCHAR[lstrlen(txt) + 1]; lstrcpy(html_text, txt); } m_doc = litehtml::document::createFromString(html_text, this, m_parent->get_html_context()); delete html_text; #endif PostMessage(m_parent->wnd(), WM_PAGE_LOADED, 0, 0); }
void web_page::import_css( litehtml::tstring& text, const litehtml::tstring& url, litehtml::tstring& baseurl ) { std::wstring css_url; t_make_url(url.c_str(), baseurl.c_str(), css_url); if(download_and_wait(css_url.c_str())) { #ifndef LITEHTML_UTF8 LPWSTR css = load_text_file(m_waited_file.c_str(), false, L"UTF-8"); if(css) { baseurl = css_url; text = css; delete css; } #else LPSTR css = (LPSTR) load_utf8_file(m_waited_file.c_str(), false, L"UTF-8"); if(css) { LPSTR css_urlA = cairo_font::wchar_to_utf8(css_url.c_str()); baseurl = css_urlA; text = css; delete css; delete css_urlA; } #endif } }
C& readlines( S const& fileName , C& container ) { S contents; S delim; // NOTE: doing these as characters skips the issue of ANSI vs Unicode delim.append(1, '\n'); load_text_file(fileName, contents); #if 0 stlsoft::string_tokeniser< S /* stlsoft::basic_string_view<ss_typename_type_k stlsoft::string_traits<S>::char_type> */ , S , stlsoft::string_tokeniser_ignore_blanks<false> > tokens(contents, delim); std::transform(tokens.begin(), tokens.end(), std::back_inserter(container), trim_trailing_carriage_return</* ss_typename_type_k */ C::value_type>()); #else /* ? 0 */ readlines_impl(contents.c_str(), contents.size(), container); #endif /* 0 */ return container; }
static bool compile_shader(GLenum shader_type, const char *filename, GLuint& shader, std::string& errors) { // load in source code for vertex shader std::string shader_src; if(!load_text_file(filename, shader_src, errors)) return false; // create a shader for it in OpenGL shader=glCreateShader(shader_type); if(shader==0){ errors.append("Couldn't create shader object\n"); return false; } // attempt to compile source const char *src_string=shader_src.c_str(); glShaderSource(shader, 1, &src_string, 0); glCompileShader(shader); GLint status; glGetShaderiv(shader, GL_COMPILE_STATUS, &status); if(status==GL_FALSE){ // problem with compilation? errors.append("Errors with file '"+std::string(filename)+"'\n"); GLint infolength; glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &infolength); std::vector<char> info(infolength, (char)0); glGetShaderInfoLog(shader, infolength, &infolength, &info[0]); errors.append(info.begin(), info.end()); return false; } // we're done! return true; }
int main (int argc, char *argv[]) { char *filename = NULL; void *ctx = ralloc(NULL, void*); char *info_log = ralloc_strdup(ctx, ""); const char *shader; int ret; if (argc) { filename = argv[1]; } shader = load_text_file (ctx, filename); if (shader == NULL) return 1; ret = glcpp_preprocess(ctx, &shader, &info_log, NULL, API_OPENGL); printf("%s", shader); fprintf(stderr, "%s", info_log); ralloc_free(ctx); return ret; }
void init( string filename ){ log_setup_1(); init_char_width(); load_text_file( logs, filename ); }
// initialize the shaders void init_shaders(ShadeState* state) { // load shader code from files auto vertex_shader_code = load_text_file("animate_vertex.glsl"); auto fragment_shader_code = load_text_file("animate_fragment.glsl"); auto vertex_shader_codes = (char *)vertex_shader_code.c_str(); auto fragment_shader_codes = (char *)fragment_shader_code.c_str(); // create shaders state->gl_vertex_shader_id = glCreateShader(GL_VERTEX_SHADER); state->gl_fragment_shader_id = glCreateShader(GL_FRAGMENT_SHADER); // load shaders code onto the GPU glShaderSource(state->gl_vertex_shader_id,1,(const char**)&vertex_shader_codes,nullptr); glShaderSource(state->gl_fragment_shader_id,1,(const char**)&fragment_shader_codes,nullptr); // compile shaders glCompileShader(state->gl_vertex_shader_id); glCompileShader(state->gl_fragment_shader_id); // check if shaders are valid error_if_glerror(); error_if_shader_not_valid(state->gl_vertex_shader_id); error_if_shader_not_valid(state->gl_fragment_shader_id); // create program state->gl_program_id = glCreateProgram(); // attach shaders glAttachShader(state->gl_program_id,state->gl_vertex_shader_id); glAttachShader(state->gl_program_id,state->gl_fragment_shader_id); // bind vertex attributes locations glBindAttribLocation(state->gl_program_id, 0, "vertex_pos"); glBindAttribLocation(state->gl_program_id, 1, "vertex_norm"); glBindAttribLocation(state->gl_program_id, 2, "vertex_texcoord"); glBindAttribLocation(state->gl_program_id, 3, "vertex_skin_bones"); glBindAttribLocation(state->gl_program_id, 4, "vertex_skin_weights"); // link program glLinkProgram(state->gl_program_id); // check if program is valid error_if_glerror(); error_if_program_not_valid(state->gl_program_id); }
BIGNUM * load_bignum(const char *name) { BIGNUM *ret = NULL; struct sshbuf *buf; buf = load_text_file(name); ASSERT_INT_NE(BN_hex2bn(&ret, (const char *)sshbuf_ptr(buf)), 0); sshbuf_free(buf); return ret; }
int main(int argc, char **argv) { if(argc < 2) { fprintf(stderr, "Must pass shader source name as argument\n"); exit(1); } const char *text = load_text_file(argv[1]); if(!text) { fprintf(stderr, "Unable to open %s\n", argv[1]); exit(1); } struct tgsi_token tokens[1024]; if(tgsi_text_translate(text, tokens, Elements(tokens))) { tgsi_dump(tokens, 0); union { struct tgsi_header h; struct tgsi_token t; } hdr; hdr.t = tokens[0]; printf("Header size: %i\n", hdr.h.HeaderSize); printf("Body size: %i\n", hdr.h.BodySize); int totalSize = hdr.h.HeaderSize + hdr.h.BodySize; for(int i=0; i<totalSize; ++i) { printf("%08x ", *((uint32_t*)&tokens[i])); } printf("\n"); /* Parsing test */ struct tgsi_parse_context ctx = {}; unsigned status = TGSI_PARSE_OK; status = tgsi_parse_init(&ctx, tokens); assert(status == TGSI_PARSE_OK); while(!tgsi_parse_end_of_tokens(&ctx)) { tgsi_parse_token(&ctx); /* declaration / immediate / instruction / property */ printf("Parsed token! %i\n", ctx.FullToken.Token.Type); } tgsi_parse_free(&ctx); } else { fprintf(stderr, "Unable to parse %s\n", argv[1]); } return 0; }
List<Font::CHAR_INFO> parseFontSpec(const String& filename) { #ifdef _DEBUG printf("\t parsing fontSpec\n"); #endif String s; if (!load_text_file(filename, &s)) { //TODO: error } ListPtr<String*> strings; s.split(strings, " \n"); uint_d size = strings.getSize(); if (*strings[0] != "#spec" && *strings[size-1] != "#end") { //TODO: log error } List<Font::CHAR_INFO> charSpec; for (uint_d i = 1; i < size; i+=5) { String& character = *strings[i]; if (character == "#end") { break; } else if (character == "" || character == "\n" || character == " ") { continue; } else { Font::CHAR_INFO cInfo; cInfo.c = character[0]; const char c = (*strings[i + 1])[0]; if (c == '#') { Font::CHAR_INFO exist = getCharInfoFromSpec(charSpec, (*strings[i + 1])[1]); exist.c = cInfo.c; charSpec << exist; }else { cInfo.xOffset = (float)atof(**strings[i + 1]); cInfo.yOffset = (float)atof(**strings[i + 2]); cInfo.cWidth = (float)atof(**strings[i + 3]); cInfo.cHeight = (float)atof(**strings[i + 4]); charSpec << cInfo; #ifdef _DEBUG printf("\t\t Retriving %c\n", cInfo.c); #endif } } } #ifdef _DEBUG printf("\t Done!\n"); #endif return charSpec; }
int main (int argc, char *argv[]) { char *filename = NULL; void *ctx = ralloc(NULL, void*); char *info_log = ralloc_strdup(ctx, ""); const char *shader; int ret; struct gl_context gl_ctx; int c; init_fake_gl_context (&gl_ctx); while ((c = getopt_long(argc, argv, "d", long_options, NULL)) != -1) { switch (c) { case DISABLE_LINE_CONTINUATIONS_OPT: gl_ctx.Const.DisableGLSLLineContinuations = true; break; case 'd': glcpp_parser_debug = 1; break; default: usage (); exit (1); } } if (optind + 1 < argc) { printf ("Unexpected argument: %s\n", argv[optind+1]); usage (); exit (1); } if (optind < argc) { filename = argv[optind]; } shader = load_text_file (ctx, filename); if (shader == NULL) return 1; _mesa_locale_init(); ret = glcpp_preprocess(ctx, &shader, &info_log, NULL, &gl_ctx); printf("%s", shader); fprintf(stderr, "%s", info_log); ralloc_free(ctx); return ret; }
/*=export_func text_mmap * private: * * what: map a text file with terminating NUL * * arg: char const*, pzFile, name of the file to map * arg: int, prot, mmap protections (see mmap(2)) * arg: int, flags, mmap flags (see mmap(2)) * arg: tmap_info_t*, mapinfo, returned info about the mapping * * ret-type: void* * ret-desc: The mmaped data address * * doc: * * This routine will mmap a file into memory ensuring that there is at least * one @file{NUL} character following the file data. It will return the * address where the file contents have been mapped into memory. If there is a * problem, then it will return @code{MAP_FAILED} and set @code{errno} * appropriately. * * The named file does not exist, @code{stat(2)} will set @code{errno} as it * will. If the file is not a regular file, @code{errno} will be * @code{EINVAL}. At that point, @code{open(2)} is attempted with the access * bits set appropriately for the requested @code{mmap(2)} protections and flag * bits. On failure, @code{errno} will be set according to the documentation * for @code{open(2)}. If @code{mmap(2)} fails, @code{errno} will be set as * that routine sets it. If @code{text_mmap} works to this point, a valid * address will be returned, but there may still be ``issues''. * * If the file size is not an even multiple of the system page size, then * @code{text_map} will return at this point and @code{errno} will be zero. * Otherwise, an anonymous map is attempted. If not available, then an attempt * is made to @code{mmap(2)} @file{/dev/zero}. If any of these fail, the * address of the file's data is returned, bug @code{no} @file{NUL} characters * are mapped after the end of the data. * * see: mmap(2), open(2), stat(2) * * err: Any error code issued by mmap(2), open(2), stat(2) is possible. * Additionally, if the specified file is not a regular file, then * errno will be set to @code{EINVAL}. * * example: * #include <mylib.h> * tmap_info_t mi; * int no_nul; * void* data = text_mmap("file", PROT_WRITE, MAP_PRIVATE, &mi); * if (data == MAP_FAILED) return; * no_nul = (mi.txt_size == mi.txt_full_size); * << use the data >> * text_munmap(&mi); =*/ void * text_mmap(char const * pzFile, int prot, int flags, tmap_info_t * mi) { validate_mmap(pzFile, prot, flags, mi); if (mi->txt_errno != 0) return MAP_FAILED_PTR; load_text_file(mi, pzFile); if (mi->txt_errno == 0) return mi->txt_data; close_mmap_files(mi); errno = mi->txt_errno; mi->txt_data = MAP_FAILED_PTR; return mi->txt_data; }
/* Load file for DUMP function */ struct TAPE_BLOCKS *load_file(char *infile,char *filefmt,char recfm,int *recl,int *recc,size_t *filesz) { struct TAPE_BLOCKS *blks; switch(filefmt[0]) { case 'B': blks=load_binary_file(infile,recfm,recl,recc,filesz); break; case 'T': blks=load_text_file(infile,recfm,recl,recc,filesz); break; case 'S': blks=load_structured_file(infile,recfm,recl,recc,filesz); break; default: fprintf(stderr,"*** INTERNAL ERROR 0001\n"); return NULL; } return blks; }
int read_path_list_file(const tchar *listfile, tchar ***paths_ret, size_t *num_paths_ret, void **mem_ret) { STRING_SET(paths); struct text_file_section tmp = { .name = T(""), .strings = &paths, }; void *buf; int ret; ret = load_text_file(listfile, &buf, &tmp, 1, NULL); if (ret) return ret; *paths_ret = paths.strings; *num_paths_ret = paths.num_strings; *mem_ret = buf; return 0; }
static const char *dd_check(struct dump_dir *dd) { unsigned dirname_len = strlen(dd->dd_dirname); char filename_buf[FILENAME_MAX+1]; strcpy(filename_buf, dd->dd_dirname); strcpy(filename_buf + dirname_len, "/"FILENAME_TIME); dd->dd_time = parse_time_file(filename_buf); if (dd->dd_time < 0) { log_debug("Missing file: "FILENAME_TIME); return FILENAME_TIME; } strcpy(filename_buf + dirname_len, "/"FILENAME_TYPE); dd->dd_type = load_text_file(filename_buf, DD_LOAD_TEXT_RETURN_NULL_ON_FAILURE); if (!dd->dd_type || (strlen(dd->dd_type) == 0)) { log_debug("Missing or empty file: "FILENAME_TYPE); return FILENAME_TYPE; } return NULL; }
int main(int argc, char **argv) { int i; char *buf; size_t bufsize; PyObject *o, *globals, *locals; Py_Initialize(); globals = PyDict_New(); locals = PyDict_New(); PyDict_SetItemString(globals, (char *)"__builtins__", PyEval_GetBuiltins()); printf("globals = %p; locals = %p;\n\n", globals, locals); Py_InitModule("tod", tod_methods); for (i = 1; i < argc; ++i) { if (load_text_file(argv[i], &buf, &bufsize) == -1) continue; printf("### Executing file %s ###\n%s###################\n", argv[1], buf); if ((o = PyRun_String(buf, Py_file_input, globals, locals)) == NULL) printf("PyRun_String returned NULL\n"); Py_XDECREF(o); printf("-------------------\n\n"); free(buf); } Py_Finalize(); return 0; }
void sshkey_file_tests(void) { struct sshkey *k1, *k2; struct sshbuf *buf, *pw; BIGNUM *a, *b, *c; char *cp; TEST_START("load passphrase"); pw = load_text_file("pw"); TEST_DONE(); TEST_START("parse RSA1 from private"); buf = load_file("rsa1_1"); ASSERT_INT_EQ(sshkey_parse_private(buf, "", "rsa1_1", &k1, NULL), 0); sshbuf_free(buf); ASSERT_PTR_NE(k1, NULL); a = load_bignum("rsa1_1.param.n"); ASSERT_BIGNUM_EQ(k1->rsa->n, a); BN_free(a); TEST_DONE(); TEST_START("parse RSA from private w/ passphrase"); buf = load_file("rsa1_1_pw"); ASSERT_INT_EQ(sshkey_parse_private(buf, sshbuf_ptr(pw), "rsa1_1_pw", &k2, NULL), 0); sshbuf_free(buf); ASSERT_PTR_NE(k2, NULL); ASSERT_INT_EQ(sshkey_equal(k1, k2), 1); sshkey_free(k2); TEST_DONE(); TEST_START("load RSA from public"); ASSERT_INT_EQ(sshkey_load_public(test_data_file("rsa1_1.pub"), &k2, NULL), 0); ASSERT_PTR_NE(k2, NULL); ASSERT_INT_EQ(sshkey_equal(k1, k2), 1); sshkey_free(k2); TEST_DONE(); TEST_START("RSA key hex fingerprint"); buf = load_text_file("rsa1_1.fp"); cp = sshkey_fingerprint(k1, SSH_FP_MD5, SSH_FP_HEX); ASSERT_PTR_NE(cp, NULL); ASSERT_STRING_EQ(cp, sshbuf_ptr(buf)); sshbuf_free(buf); free(cp); TEST_DONE(); TEST_START("RSA key bubblebabble fingerprint"); buf = load_text_file("rsa1_1.fp.bb"); cp = sshkey_fingerprint(k1, SSH_FP_SHA1, SSH_FP_BUBBLEBABBLE); ASSERT_PTR_NE(cp, NULL); ASSERT_STRING_EQ(cp, sshbuf_ptr(buf)); sshbuf_free(buf); free(cp); TEST_DONE(); sshkey_free(k1); TEST_START("parse RSA from private"); buf = load_file("rsa_1"); ASSERT_INT_EQ(sshkey_parse_private(buf, "", "rsa_1", &k1, NULL), 0); sshbuf_free(buf); ASSERT_PTR_NE(k1, NULL); a = load_bignum("rsa_1.param.n"); b = load_bignum("rsa_1.param.p"); c = load_bignum("rsa_1.param.q"); ASSERT_BIGNUM_EQ(k1->rsa->n, a); ASSERT_BIGNUM_EQ(k1->rsa->p, b); ASSERT_BIGNUM_EQ(k1->rsa->q, c); BN_free(a); BN_free(b); BN_free(c); TEST_DONE(); TEST_START("parse RSA from private w/ passphrase"); buf = load_file("rsa_1_pw"); ASSERT_INT_EQ(sshkey_parse_private(buf, sshbuf_ptr(pw), "rsa_1_pw", &k2, NULL), 0); sshbuf_free(buf); ASSERT_PTR_NE(k2, NULL); ASSERT_INT_EQ(sshkey_equal(k1, k2), 1); sshkey_free(k2); TEST_DONE(); TEST_START("load RSA from public"); ASSERT_INT_EQ(sshkey_load_public(test_data_file("rsa_1.pub"), &k2, NULL), 0); ASSERT_PTR_NE(k2, NULL); ASSERT_INT_EQ(sshkey_equal(k1, k2), 1); sshkey_free(k2); TEST_DONE(); TEST_START("RSA key hex fingerprint"); buf = load_text_file("rsa_1.fp"); cp = sshkey_fingerprint(k1, SSH_FP_MD5, SSH_FP_HEX); ASSERT_PTR_NE(cp, NULL); ASSERT_STRING_EQ(cp, sshbuf_ptr(buf)); sshbuf_free(buf); free(cp); TEST_DONE(); TEST_START("RSA key bubblebabble fingerprint"); buf = load_text_file("rsa_1.fp.bb"); cp = sshkey_fingerprint(k1, SSH_FP_SHA1, SSH_FP_BUBBLEBABBLE); ASSERT_PTR_NE(cp, NULL); ASSERT_STRING_EQ(cp, sshbuf_ptr(buf)); sshbuf_free(buf); free(cp); TEST_DONE(); sshkey_free(k1); TEST_START("parse DSA from private"); buf = load_file("dsa_1"); ASSERT_INT_EQ(sshkey_parse_private(buf, "", "dsa_1", &k1, NULL), 0); sshbuf_free(buf); ASSERT_PTR_NE(k1, NULL); a = load_bignum("dsa_1.param.g"); b = load_bignum("dsa_1.param.priv"); c = load_bignum("dsa_1.param.pub"); ASSERT_BIGNUM_EQ(k1->dsa->g, a); ASSERT_BIGNUM_EQ(k1->dsa->priv_key, b); ASSERT_BIGNUM_EQ(k1->dsa->pub_key, c); BN_free(a); BN_free(b); BN_free(c); TEST_DONE(); TEST_START("parse DSA from private w/ passphrase"); buf = load_file("dsa_1_pw"); ASSERT_INT_EQ(sshkey_parse_private(buf, sshbuf_ptr(pw), "dsa_1_pw", &k2, NULL), 0); sshbuf_free(buf); ASSERT_PTR_NE(k2, NULL); ASSERT_INT_EQ(sshkey_equal(k1, k2), 1); sshkey_free(k2); TEST_DONE(); TEST_START("load DSA from public"); ASSERT_INT_EQ(sshkey_load_public(test_data_file("dsa_1.pub"), &k2, NULL), 0); ASSERT_PTR_NE(k2, NULL); ASSERT_INT_EQ(sshkey_equal(k1, k2), 1); sshkey_free(k2); TEST_DONE(); TEST_START("DSA key hex fingerprint"); buf = load_text_file("dsa_1.fp"); cp = sshkey_fingerprint(k1, SSH_FP_MD5, SSH_FP_HEX); ASSERT_PTR_NE(cp, NULL); ASSERT_STRING_EQ(cp, sshbuf_ptr(buf)); sshbuf_free(buf); free(cp); TEST_DONE(); TEST_START("DSA key bubblebabble fingerprint"); buf = load_text_file("dsa_1.fp.bb"); cp = sshkey_fingerprint(k1, SSH_FP_SHA1, SSH_FP_BUBBLEBABBLE); ASSERT_PTR_NE(cp, NULL); ASSERT_STRING_EQ(cp, sshbuf_ptr(buf)); sshbuf_free(buf); free(cp); TEST_DONE(); sshkey_free(k1); TEST_START("parse ECDSA from private"); buf = load_file("ecdsa_1"); ASSERT_INT_EQ(sshkey_parse_private(buf, "", "ecdsa_1", &k1, NULL), 0); sshbuf_free(buf); ASSERT_PTR_NE(k1, NULL); buf = load_text_file("ecdsa_1.param.curve"); ASSERT_STRING_EQ(sshbuf_ptr(buf), OBJ_nid2sn(k1->ecdsa_nid)); sshbuf_free(buf); a = load_bignum("ecdsa_1.param.priv"); b = load_bignum("ecdsa_1.param.pub"); c = EC_POINT_point2bn(EC_KEY_get0_group(k1->ecdsa), EC_KEY_get0_public_key(k1->ecdsa), POINT_CONVERSION_UNCOMPRESSED, NULL, NULL); ASSERT_PTR_NE(c, NULL); ASSERT_BIGNUM_EQ(EC_KEY_get0_private_key(k1->ecdsa), a); ASSERT_BIGNUM_EQ(b, c); BN_free(a); BN_free(b); BN_free(c); TEST_DONE(); TEST_START("parse ECDSA from private w/ passphrase"); buf = load_file("ecdsa_1_pw"); ASSERT_INT_EQ(sshkey_parse_private(buf, sshbuf_ptr(pw), "ecdsa_1_pw", &k2, NULL), 0); sshbuf_free(buf); ASSERT_PTR_NE(k2, NULL); ASSERT_INT_EQ(sshkey_equal(k1, k2), 1); sshkey_free(k2); TEST_DONE(); TEST_START("load ECDSA from public"); ASSERT_INT_EQ(sshkey_load_public(test_data_file("ecdsa_1.pub"), &k2, NULL), 0); ASSERT_PTR_NE(k2, NULL); ASSERT_INT_EQ(sshkey_equal(k1, k2), 1); sshkey_free(k2); TEST_DONE(); TEST_START("ECDSA key hex fingerprint"); buf = load_text_file("ecdsa_1.fp"); cp = sshkey_fingerprint(k1, SSH_FP_MD5, SSH_FP_HEX); ASSERT_PTR_NE(cp, NULL); ASSERT_STRING_EQ(cp, sshbuf_ptr(buf)); sshbuf_free(buf); free(cp); TEST_DONE(); TEST_START("ECDSA key bubblebabble fingerprint"); buf = load_text_file("ecdsa_1.fp.bb"); cp = sshkey_fingerprint(k1, SSH_FP_SHA1, SSH_FP_BUBBLEBABBLE); ASSERT_PTR_NE(cp, NULL); ASSERT_STRING_EQ(cp, sshbuf_ptr(buf)); sshbuf_free(buf); free(cp); TEST_DONE(); sshkey_free(k1); sshbuf_free(pw); }
void sshkey_file_tests(void) { struct sshkey *k1, *k2; struct sshbuf *buf, *pw; BIGNUM *a, *b, *c; char *cp; TEST_START("load passphrase"); pw = load_text_file("pw"); TEST_DONE(); #ifdef WITH_SSH1 TEST_START("parse RSA1 from private"); buf = load_file("rsa1_1"); ASSERT_INT_EQ(sshkey_parse_private_fileblob(buf, "", "rsa1_1", &k1, NULL), 0); sshbuf_free(buf); ASSERT_PTR_NE(k1, NULL); a = load_bignum("rsa1_1.param.n"); ASSERT_BIGNUM_EQ(k1->rsa->n, a); BN_free(a); TEST_DONE(); TEST_START("parse RSA1 from private w/ passphrase"); buf = load_file("rsa1_1_pw"); ASSERT_INT_EQ(sshkey_parse_private_fileblob(buf, (const char *)sshbuf_ptr(pw), "rsa1_1_pw", &k2, NULL), 0); sshbuf_free(buf); ASSERT_PTR_NE(k2, NULL); ASSERT_INT_EQ(sshkey_equal(k1, k2), 1); sshkey_free(k2); TEST_DONE(); TEST_START("load RSA1 from public"); ASSERT_INT_EQ(sshkey_load_public(test_data_file("rsa1_1.pub"), &k2, NULL), 0); ASSERT_PTR_NE(k2, NULL); ASSERT_INT_EQ(sshkey_equal(k1, k2), 1); sshkey_free(k2); TEST_DONE(); TEST_START("RSA1 key hex fingerprint"); buf = load_text_file("rsa1_1.fp"); cp = sshkey_fingerprint(k1, SSH_DIGEST_MD5, SSH_FP_HEX); ASSERT_PTR_NE(cp, NULL); ASSERT_STRING_EQ(cp, (const char *)sshbuf_ptr(buf)); sshbuf_free(buf); free(cp); TEST_DONE(); TEST_START("RSA1 key bubblebabble fingerprint"); buf = load_text_file("rsa1_1.fp.bb"); cp = sshkey_fingerprint(k1, SSH_DIGEST_SHA1, SSH_FP_BUBBLEBABBLE); ASSERT_PTR_NE(cp, NULL); ASSERT_STRING_EQ(cp, (const char *)sshbuf_ptr(buf)); sshbuf_free(buf); free(cp); TEST_DONE(); sshkey_free(k1); #endif TEST_START("parse RSA from private"); buf = load_file("rsa_1"); ASSERT_INT_EQ(sshkey_parse_private_fileblob(buf, "", "rsa_1", &k1, NULL), 0); sshbuf_free(buf); ASSERT_PTR_NE(k1, NULL); a = load_bignum("rsa_1.param.n"); b = load_bignum("rsa_1.param.p"); c = load_bignum("rsa_1.param.q"); ASSERT_BIGNUM_EQ(k1->rsa->n, a); ASSERT_BIGNUM_EQ(k1->rsa->p, b); ASSERT_BIGNUM_EQ(k1->rsa->q, c); BN_free(a); BN_free(b); BN_free(c); TEST_DONE(); TEST_START("parse RSA from private w/ passphrase"); buf = load_file("rsa_1_pw"); ASSERT_INT_EQ(sshkey_parse_private_fileblob(buf, (const char *)sshbuf_ptr(pw), "rsa_1_pw", &k2, NULL), 0); sshbuf_free(buf); ASSERT_PTR_NE(k2, NULL); ASSERT_INT_EQ(sshkey_equal(k1, k2), 1); sshkey_free(k2); TEST_DONE(); TEST_START("parse RSA from new-format"); buf = load_file("rsa_n"); ASSERT_INT_EQ(sshkey_parse_private_fileblob(buf, "", "rsa_n", &k2, NULL), 0); sshbuf_free(buf); ASSERT_PTR_NE(k2, NULL); ASSERT_INT_EQ(sshkey_equal(k1, k2), 1); sshkey_free(k2); TEST_DONE(); TEST_START("parse RSA from new-format w/ passphrase"); buf = load_file("rsa_n_pw"); ASSERT_INT_EQ(sshkey_parse_private_fileblob(buf, (const char *)sshbuf_ptr(pw), "rsa_n_pw", &k2, NULL), 0); sshbuf_free(buf); ASSERT_PTR_NE(k2, NULL); ASSERT_INT_EQ(sshkey_equal(k1, k2), 1); sshkey_free(k2); TEST_DONE(); TEST_START("load RSA from public"); ASSERT_INT_EQ(sshkey_load_public(test_data_file("rsa_1.pub"), &k2, NULL), 0); ASSERT_PTR_NE(k2, NULL); ASSERT_INT_EQ(sshkey_equal(k1, k2), 1); sshkey_free(k2); TEST_DONE(); TEST_START("load RSA cert"); ASSERT_INT_EQ(sshkey_load_cert(test_data_file("rsa_1"), &k2), 0); ASSERT_PTR_NE(k2, NULL); ASSERT_INT_EQ(k2->type, KEY_RSA_CERT); ASSERT_INT_EQ(sshkey_equal(k1, k2), 0); ASSERT_INT_EQ(sshkey_equal_public(k1, k2), 1); TEST_DONE(); TEST_START("RSA key hex fingerprint"); buf = load_text_file("rsa_1.fp"); cp = sshkey_fingerprint(k1, SSH_DIGEST_MD5, SSH_FP_HEX); ASSERT_PTR_NE(cp, NULL); ASSERT_STRING_EQ(cp, (const char *)sshbuf_ptr(buf)); sshbuf_free(buf); free(cp); TEST_DONE(); TEST_START("RSA cert hex fingerprint"); buf = load_text_file("rsa_1-cert.fp"); cp = sshkey_fingerprint(k2, SSH_DIGEST_MD5, SSH_FP_HEX); ASSERT_PTR_NE(cp, NULL); ASSERT_STRING_EQ(cp, (const char *)sshbuf_ptr(buf)); sshbuf_free(buf); free(cp); sshkey_free(k2); TEST_DONE(); TEST_START("RSA key bubblebabble fingerprint"); buf = load_text_file("rsa_1.fp.bb"); cp = sshkey_fingerprint(k1, SSH_DIGEST_SHA1, SSH_FP_BUBBLEBABBLE); ASSERT_PTR_NE(cp, NULL); ASSERT_STRING_EQ(cp, (const char *)sshbuf_ptr(buf)); sshbuf_free(buf); free(cp); TEST_DONE(); sshkey_free(k1); TEST_START("parse DSA from private"); buf = load_file("dsa_1"); ASSERT_INT_EQ(sshkey_parse_private_fileblob(buf, "", "dsa_1", &k1, NULL), 0); sshbuf_free(buf); ASSERT_PTR_NE(k1, NULL); a = load_bignum("dsa_1.param.g"); b = load_bignum("dsa_1.param.priv"); c = load_bignum("dsa_1.param.pub"); ASSERT_BIGNUM_EQ(k1->dsa->g, a); ASSERT_BIGNUM_EQ(k1->dsa->priv_key, b); ASSERT_BIGNUM_EQ(k1->dsa->pub_key, c); BN_free(a); BN_free(b); BN_free(c); TEST_DONE(); TEST_START("parse DSA from private w/ passphrase"); buf = load_file("dsa_1_pw"); ASSERT_INT_EQ(sshkey_parse_private_fileblob(buf, (const char *)sshbuf_ptr(pw), "dsa_1_pw", &k2, NULL), 0); sshbuf_free(buf); ASSERT_PTR_NE(k2, NULL); ASSERT_INT_EQ(sshkey_equal(k1, k2), 1); sshkey_free(k2); TEST_DONE(); TEST_START("parse DSA from new-format"); buf = load_file("dsa_n"); ASSERT_INT_EQ(sshkey_parse_private_fileblob(buf, "", "dsa_n", &k2, NULL), 0); sshbuf_free(buf); ASSERT_PTR_NE(k2, NULL); ASSERT_INT_EQ(sshkey_equal(k1, k2), 1); sshkey_free(k2); TEST_DONE(); TEST_START("parse DSA from new-format w/ passphrase"); buf = load_file("dsa_n_pw"); ASSERT_INT_EQ(sshkey_parse_private_fileblob(buf, (const char *)sshbuf_ptr(pw), "dsa_n_pw", &k2, NULL), 0); sshbuf_free(buf); ASSERT_PTR_NE(k2, NULL); ASSERT_INT_EQ(sshkey_equal(k1, k2), 1); sshkey_free(k2); TEST_DONE(); TEST_START("load DSA from public"); ASSERT_INT_EQ(sshkey_load_public(test_data_file("dsa_1.pub"), &k2, NULL), 0); ASSERT_PTR_NE(k2, NULL); ASSERT_INT_EQ(sshkey_equal(k1, k2), 1); sshkey_free(k2); TEST_DONE(); TEST_START("load DSA cert"); ASSERT_INT_EQ(sshkey_load_cert(test_data_file("dsa_1"), &k2), 0); ASSERT_PTR_NE(k2, NULL); ASSERT_INT_EQ(k2->type, KEY_DSA_CERT); ASSERT_INT_EQ(sshkey_equal(k1, k2), 0); ASSERT_INT_EQ(sshkey_equal_public(k1, k2), 1); TEST_DONE(); TEST_START("DSA key hex fingerprint"); buf = load_text_file("dsa_1.fp"); cp = sshkey_fingerprint(k1, SSH_DIGEST_MD5, SSH_FP_HEX); ASSERT_PTR_NE(cp, NULL); ASSERT_STRING_EQ(cp, (const char *)sshbuf_ptr(buf)); sshbuf_free(buf); free(cp); TEST_DONE(); TEST_START("DSA cert hex fingerprint"); buf = load_text_file("dsa_1-cert.fp"); cp = sshkey_fingerprint(k2, SSH_DIGEST_MD5, SSH_FP_HEX); ASSERT_PTR_NE(cp, NULL); ASSERT_STRING_EQ(cp, (const char *)sshbuf_ptr(buf)); sshbuf_free(buf); free(cp); sshkey_free(k2); TEST_DONE(); TEST_START("DSA key bubblebabble fingerprint"); buf = load_text_file("dsa_1.fp.bb"); cp = sshkey_fingerprint(k1, SSH_DIGEST_SHA1, SSH_FP_BUBBLEBABBLE); ASSERT_PTR_NE(cp, NULL); ASSERT_STRING_EQ(cp, (const char *)sshbuf_ptr(buf)); sshbuf_free(buf); free(cp); TEST_DONE(); sshkey_free(k1); #ifdef OPENSSL_HAS_ECC TEST_START("parse ECDSA from private"); buf = load_file("ecdsa_1"); ASSERT_INT_EQ(sshkey_parse_private_fileblob(buf, "", "ecdsa_1", &k1, NULL), 0); sshbuf_free(buf); ASSERT_PTR_NE(k1, NULL); buf = load_text_file("ecdsa_1.param.curve"); ASSERT_STRING_EQ((const char *)sshbuf_ptr(buf), OBJ_nid2sn(k1->ecdsa_nid)); sshbuf_free(buf); a = load_bignum("ecdsa_1.param.priv"); b = load_bignum("ecdsa_1.param.pub"); c = EC_POINT_point2bn(EC_KEY_get0_group(k1->ecdsa), EC_KEY_get0_public_key(k1->ecdsa), POINT_CONVERSION_UNCOMPRESSED, NULL, NULL); ASSERT_PTR_NE(c, NULL); ASSERT_BIGNUM_EQ(EC_KEY_get0_private_key(k1->ecdsa), a); ASSERT_BIGNUM_EQ(b, c); BN_free(a); BN_free(b); BN_free(c); TEST_DONE(); TEST_START("parse ECDSA from private w/ passphrase"); buf = load_file("ecdsa_1_pw"); ASSERT_INT_EQ(sshkey_parse_private_fileblob(buf, (const char *)sshbuf_ptr(pw), "ecdsa_1_pw", &k2, NULL), 0); sshbuf_free(buf); ASSERT_PTR_NE(k2, NULL); ASSERT_INT_EQ(sshkey_equal(k1, k2), 1); sshkey_free(k2); TEST_DONE(); TEST_START("parse ECDSA from new-format"); buf = load_file("ecdsa_n"); ASSERT_INT_EQ(sshkey_parse_private_fileblob(buf, "", "ecdsa_n", &k2, NULL), 0); sshbuf_free(buf); ASSERT_PTR_NE(k2, NULL); ASSERT_INT_EQ(sshkey_equal(k1, k2), 1); sshkey_free(k2); TEST_DONE(); TEST_START("parse ECDSA from new-format w/ passphrase"); buf = load_file("ecdsa_n_pw"); ASSERT_INT_EQ(sshkey_parse_private_fileblob(buf, (const char *)sshbuf_ptr(pw), "ecdsa_n_pw", &k2, NULL), 0); sshbuf_free(buf); ASSERT_PTR_NE(k2, NULL); ASSERT_INT_EQ(sshkey_equal(k1, k2), 1); sshkey_free(k2); TEST_DONE(); TEST_START("load ECDSA from public"); ASSERT_INT_EQ(sshkey_load_public(test_data_file("ecdsa_1.pub"), &k2, NULL), 0); ASSERT_PTR_NE(k2, NULL); ASSERT_INT_EQ(sshkey_equal(k1, k2), 1); sshkey_free(k2); TEST_DONE(); TEST_START("load ECDSA cert"); ASSERT_INT_EQ(sshkey_load_cert(test_data_file("ecdsa_1"), &k2), 0); ASSERT_PTR_NE(k2, NULL); ASSERT_INT_EQ(k2->type, KEY_ECDSA_CERT); ASSERT_INT_EQ(sshkey_equal(k1, k2), 0); ASSERT_INT_EQ(sshkey_equal_public(k1, k2), 1); TEST_DONE(); TEST_START("ECDSA key hex fingerprint"); buf = load_text_file("ecdsa_1.fp"); cp = sshkey_fingerprint(k1, SSH_DIGEST_MD5, SSH_FP_HEX); ASSERT_PTR_NE(cp, NULL); ASSERT_STRING_EQ(cp, (const char *)sshbuf_ptr(buf)); sshbuf_free(buf); free(cp); TEST_DONE(); TEST_START("ECDSA cert hex fingerprint"); buf = load_text_file("ecdsa_1-cert.fp"); cp = sshkey_fingerprint(k2, SSH_DIGEST_MD5, SSH_FP_HEX); ASSERT_PTR_NE(cp, NULL); ASSERT_STRING_EQ(cp, (const char *)sshbuf_ptr(buf)); sshbuf_free(buf); free(cp); sshkey_free(k2); TEST_DONE(); TEST_START("ECDSA key bubblebabble fingerprint"); buf = load_text_file("ecdsa_1.fp.bb"); cp = sshkey_fingerprint(k1, SSH_DIGEST_SHA1, SSH_FP_BUBBLEBABBLE); ASSERT_PTR_NE(cp, NULL); ASSERT_STRING_EQ(cp, (const char *)sshbuf_ptr(buf)); sshbuf_free(buf); free(cp); TEST_DONE(); sshkey_free(k1); #endif /* OPENSSL_HAS_ECC */ TEST_START("parse Ed25519 from private"); buf = load_file("ed25519_1"); ASSERT_INT_EQ(sshkey_parse_private_fileblob(buf, "", "ed25519_1", &k1, NULL), 0); sshbuf_free(buf); ASSERT_PTR_NE(k1, NULL); ASSERT_INT_EQ(k1->type, KEY_ED25519); /* XXX check key contents */ TEST_DONE(); TEST_START("parse Ed25519 from private w/ passphrase"); buf = load_file("ed25519_1_pw"); ASSERT_INT_EQ(sshkey_parse_private_fileblob(buf, (const char *)sshbuf_ptr(pw), "ed25519_1_pw", &k2, NULL), 0); sshbuf_free(buf); ASSERT_PTR_NE(k2, NULL); ASSERT_INT_EQ(sshkey_equal(k1, k2), 1); sshkey_free(k2); TEST_DONE(); TEST_START("load Ed25519 from public"); ASSERT_INT_EQ(sshkey_load_public(test_data_file("ed25519_1.pub"), &k2, NULL), 0); ASSERT_PTR_NE(k2, NULL); ASSERT_INT_EQ(sshkey_equal(k1, k2), 1); sshkey_free(k2); TEST_DONE(); TEST_START("load Ed25519 cert"); ASSERT_INT_EQ(sshkey_load_cert(test_data_file("ed25519_1"), &k2), 0); ASSERT_PTR_NE(k2, NULL); ASSERT_INT_EQ(k2->type, KEY_ED25519_CERT); ASSERT_INT_EQ(sshkey_equal(k1, k2), 0); ASSERT_INT_EQ(sshkey_equal_public(k1, k2), 1); TEST_DONE(); TEST_START("Ed25519 key hex fingerprint"); buf = load_text_file("ed25519_1.fp"); cp = sshkey_fingerprint(k1, SSH_DIGEST_MD5, SSH_FP_HEX); ASSERT_PTR_NE(cp, NULL); ASSERT_STRING_EQ(cp, (const char *)sshbuf_ptr(buf)); sshbuf_free(buf); free(cp); TEST_DONE(); TEST_START("Ed25519 cert hex fingerprint"); buf = load_text_file("ed25519_1-cert.fp"); cp = sshkey_fingerprint(k2, SSH_DIGEST_MD5, SSH_FP_HEX); ASSERT_PTR_NE(cp, NULL); ASSERT_STRING_EQ(cp, (const char *)sshbuf_ptr(buf)); sshbuf_free(buf); free(cp); sshkey_free(k2); TEST_DONE(); TEST_START("Ed25519 key bubblebabble fingerprint"); buf = load_text_file("ed25519_1.fp.bb"); cp = sshkey_fingerprint(k1, SSH_DIGEST_SHA1, SSH_FP_BUBBLEBABBLE); ASSERT_PTR_NE(cp, NULL); ASSERT_STRING_EQ(cp, (const char *)sshbuf_ptr(buf)); sshbuf_free(buf); free(cp); TEST_DONE(); sshkey_free(k1); sshbuf_free(pw); }