1/*****************************************************************************
2
3Copyright (c) 2015, 2017, MariaDB Corporation.
4
5This program is free software; you can redistribute it and/or modify it under
6the terms of the GNU General Public License as published by the Free Software
7Foundation; version 2 of the License.
8
9This program is distributed in the hope that it will be useful, but WITHOUT
10ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
12
13You should have received a copy of the GNU General Public License along with
14this program; if not, write to the Free Software Foundation, Inc.,
1551 Franklin Street, Suite 500, Boston, MA 02110-1335 USA
16
17*****************************************************************************/
18
19/**************************************************//**
20@file include/fil0crypt.ic
21The low-level file system encryption support functions
22
23Created 04/01/2015 Jan Lindström
24*******************************************************/
25
26/*******************************************************************//**
27Find out whether the page is page encrypted
28@return true if page is page encrypted, false if not */
29UNIV_INLINE
30bool
31fil_page_is_encrypted(
32/*==================*/
33 const byte *buf) /*!< in: page */
34{
35 return(mach_read_from_4(buf+FIL_PAGE_FILE_FLUSH_LSN_OR_KEY_VERSION) != 0);
36}
37
38/*******************************************************************//**
39Get current encryption mode from crypt_data.
40@return string representation */
41UNIV_INLINE
42const char *
43fil_crypt_get_mode(
44/*===============*/
45 const fil_space_crypt_t* crypt_data)
46{
47 switch (crypt_data->encryption) {
48 case FIL_ENCRYPTION_DEFAULT:
49 return("Default tablespace encryption mode");
50 case FIL_ENCRYPTION_ON:
51 return("Tablespace encrypted");
52 case FIL_ENCRYPTION_OFF:
53 return("Tablespace not encrypted");
54 }
55
56 ut_error;
57 return ("NULL");
58}
59
60/*******************************************************************//**
61Get current encryption type from crypt_data.
62@return string representation */
63UNIV_INLINE
64const char *
65fil_crypt_get_type(
66 const fil_space_crypt_t* crypt_data)
67{
68 ut_ad(crypt_data != NULL);
69 switch (crypt_data->type) {
70 case CRYPT_SCHEME_UNENCRYPTED:
71 return("scheme unencrypted");
72 break;
73 case CRYPT_SCHEME_1:
74 return("scheme encrypted");
75 break;
76 default:
77 ut_error;
78 }
79
80 return ("NULL");
81}
82