Coverage Report

Created: 2025-07-18 07:04

/src/sleuthkit/tsk/auto/guid.h
Line
Count
Source (jump to first uncovered line)
1
/*
2
The MIT License (MIT)
3
4
Copyright (c) 2014 Graeme Hill (http://graemehill.ca)
5
6
Permission is hereby granted, free of charge, to any person obtaining a copy
7
of this software and associated documentation files (the "Software"), to deal
8
in the Software without restriction, including without limitation the rights
9
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
copies of the Software, and to permit persons to whom the Software is
11
furnished to do so, subject to the following conditions:
12
13
The above copyright notice and this permission notice shall be included in
14
all copies or substantial portions of the Software.
15
16
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22
THE SOFTWARE.
23
*/
24
25
#pragma once
26
27
#include <iostream>
28
#include <vector>
29
#include <sstream>
30
#include <string>
31
#include <iomanip>
32
33
#ifdef GUID_ANDROID
34
#include <jni.h>
35
#endif
36
37
// Class to represent a GUID/UUID. Each instance acts as a wrapper around a
38
// 16 byte value that can be passed around by value. It also supports
39
// conversion to string (via the stream operator <<) and conversion from a
40
// string via constructor.
41
class TSKGuid
42
{
43
  public:
44
45
    // create a guid from vector of bytes
46
    TSKGuid(const std::vector<unsigned char> &bytes);
47
48
    // create a guid from array of bytes
49
    TSKGuid(const unsigned char *bytes);
50
51
    // create a guid from string
52
    TSKGuid(const std::string &fromString);
53
54
    // create empty guid
55
    TSKGuid();
56
57
0
    TSKGuid(TSKGuid &&) = default;
58
59
    // copy constructor
60
    TSKGuid(const TSKGuid &other);
61
62
    // overload assignment operator
63
    TSKGuid &operator=(const TSKGuid &other);
64
0
    TSKGuid &operator=(TSKGuid &&) = default;
65
66
    // overload equality and inequality operator
67
    bool operator==(const TSKGuid &other) const;
68
    bool operator!=(const TSKGuid &other) const;
69
70
    std::string str() const;
71
72
0
    inline const std::vector<unsigned char> & bytes() const noexcept {
73
0
        return _bytes;
74
0
    }
75
76
  private:
77
78
    // actual data
79
    std::vector<unsigned char> _bytes;
80
81
    // make the << operator a friend so it can access _bytes
82
    friend std::ostream &operator<<(std::ostream &s, const TSKGuid &guid);
83
};
84
85
// Class that can create new guids. The only reason this exists instead of
86
// just a global "newGuid" function is because some platforms will require
87
// that there is some attached context. In the case of android, we need to
88
// know what JNIEnv is being used to call back to Java, but the newGuid()
89
// function would no longer be cross-platform if we parameterized the android
90
// version. Instead, construction of the GuidGenerator may be different on
91
// each platform, but the use of newGuid is uniform.
92
class GuidGenerator
93
{
94
  public:
95
#ifdef GUID_ANDROID
96
    GuidGenerator(JNIEnv *env);
97
#else
98
0
    GuidGenerator() { }
99
#endif
100
101
    TSKGuid newGuid();
102
103
#ifdef GUID_ANDROID
104
  private:
105
    JNIEnv *_env;
106
    jclass _uuidClass;
107
    jmethodID _newGuidMethod;
108
    jmethodID _mostSignificantBitsMethod;
109
    jmethodID _leastSignificantBitsMethod;
110
#endif
111
};