- EXPECT_EQ(READ_WRITE_BLOCK_N, fread(crtDer.data, crtDer.len, READ_WRITE_BLOCK_N, fileCert));
- fclose(fileCert);
-
- ByteArray pubKey = BYTE_ARRAY_INITIALIZER;
- FILE * fileKey = fopen("capub.der", "rb");
- ASSERT_TRUE(fileKey != NULL);
- fseek(fileKey, 0, SEEK_END);
- pubKey.len = ftell(fileKey);
- fseek(fileKey, 0, SEEK_SET);
- //openssl generates a public key that is longer than 64 bytes
- //with additional 27 bytes prepending the actual key
- if(pubKey.len > PUBLIC_KEY_SIZE){
- fseek(fileKey, (pubKey.len - PUBLIC_KEY_SIZE), SEEK_SET);
- pubKey.len = PUBLIC_KEY_SIZE;
+ int res = read(fileCert, crtDer.data, crtDer.len);
+ ASSERT_NE(-1, res);
+ EXPECT_EQ(st.st_size, res);
+ close(fileCert);
+
+ //open file
+ int fileKey = open("capub.der", O_RDONLY);
+ ASSERT_TRUE(fileKey != -1);
+ //get status
+ ASSERT_TRUE(fstat(fileKey, &st) == 0);
+
+ if(st.st_size > PUBLIC_KEY_SIZE)
+ {
+ ASSERT_NE(-1, lseek(fileKey, (st.st_size - PUBLIC_KEY_SIZE), SEEK_SET));