Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
C
CPTR 245 - Lab Repository
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Metrics
Incidents
Environments
Packages & Registries
Packages & Registries
Package Registry
Container Registry
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Bradon Ladd
CPTR 245 - Lab Repository
Commits
88c711c8
Commit
88c711c8
authored
Mar 02, 2022
by
Bradon Ladd
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Adding lab13 dir
parent
0f8901ca
Pipeline
#21364
waiting for manual action with stage
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
60 additions
and
0 deletions
+60
-0
lab-13/main1.cpp
lab-13/main1.cpp
+60
-0
No files found.
lab-13/main1.cpp
0 → 100644
View file @
88c711c8
/*
* main1.cpp for CPTR 245 Lab 13 on libraries and versions
*/
#include <fstream> // std::ifstream
#include <iomanip> // std::setfill, std::setw
#include <iostream> // std::cout, std::endl
#include <sys/stat.h> // stat() to get file size
#include <openssl/crypto.h>
#include <openssl/md5.h>
int
main
(
int
argc
,
char
*
argv
[])
{
// verify proper command-line arguments
if
(
argc
!=
2
)
{
std
::
cerr
<<
"USAGE: ./a.out FILEPATH"
<<
std
::
endl
;
exit
(
1
);
}
// print version found in header file
std
::
cout
<<
"SSL Header Version: "
<<
OPENSSL_VERSION_TEXT
<<
std
::
endl
;
// print version found in library linked at runtime
std
::
cout
<<
"SSL Library Version: "
<<
OpenSSL_version
(
OPENSSL_VERSION
)
<<
std
::
endl
;
// get file size
struct
stat
statbuf
;
if
(
stat
(
argv
[
1
],
&
statbuf
)
<
0
)
{
std
::
cerr
<<
"Unable to get info on the file"
<<
std
::
endl
;
exit
(
1
);
}
int
fileSize
=
statbuf
.
st_size
;
// open and read file into new buffer
char
*
buffer
=
new
char
[
fileSize
];
std
::
ifstream
inFS
(
argv
[
1
]);
if
(
!
inFS
.
is_open
())
{
std
::
cerr
<<
"Could not open file "
<<
argv
[
1
]
<<
'.'
<<
std
::
endl
;
return
1
;
}
inFS
.
read
(
buffer
,
fileSize
);
inFS
.
close
();
// calculate MD5
unsigned
char
result
[
MD5_DIGEST_LENGTH
];
MD5
((
unsigned
char
*
)
buffer
,
fileSize
,
result
);
// print MD5 in hex digits
for
(
int
i
=
0
;
i
<
MD5_DIGEST_LENGTH
;
i
++
)
{
std
::
cout
<<
std
::
setw
(
2
)
<<
std
::
setfill
(
'0'
)
<<
std
::
hex
<<
(
int
)
result
[
i
];
}
std
::
cout
<<
std
::
dec
<<
" "
<<
argv
[
1
]
<<
'('
<<
fileSize
<<
')'
<<
std
::
endl
;
// free allocated memory and return
delete
[]
buffer
;
return
0
;
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment