1#!/bin/ksh -p
2#
3# CDDL HEADER START
4#
5# This file and its contents are supplied under the terms of the
6# Common Development and Distribution License ("CDDL"), version 1.0.
7# You may only use this file in accordance with the terms of version
8# 1.0 of the CDDL.
9#
10# A full copy of the text of the CDDL should have accompanied this
11# source.  A copy of the CDDL is also available via the Internet at
12# http://www.illumos.org/license/CDDL.
13#
14# CDDL HEADER END
15#
16
17#
18# Copyright (c) 2017 Datto, Inc. All rights reserved.
19#
20
21. $STF_SUITE/include/libtest.shlib
22. $STF_SUITE/tests/functional/cli_root/zfs_load-key/zfs_load-key.cfg
23
24# Return 0 is a dataset key is available, 1 otherwise
25#
26# $1 - dataset
27#
28function key_available
29{
30	typeset ds=$1
31
32	datasetexists $ds || return 1
33
34	typeset val=$(get_prop keystatus $ds)
35	if [[ "$val" == "none" ]]; then
36		log_note "Dataset $ds is not encrypted"
37	elif [[ "$val" == "available" ]]; then
38		return 0
39	fi
40
41	return 1
42}
43
44function key_unavailable
45{
46	key_available $1 && return 1
47	return 0
48}
49
50function verify_keyformat
51{
52	typeset ds=$1
53	typeset format=$2
54	typeset fmt=$(get_prop keyformat $ds)
55
56	if [[ "$fmt" != "$format" ]]; then
57		log_fail "Expected keyformat $format, got $fmt"
58	fi
59
60	return 0
61}
62
63function verify_keylocation
64{
65	typeset ds=$1
66	typeset location=$2
67	typeset keyloc=$(get_prop keylocation $ds)
68
69	if [[ "$keyloc" != "$location" ]]; then
70		log_fail "Expected keylocation $location, got $keyloc"
71	fi
72
73	return 0
74}
75
76function verify_encryption_root
77{
78	typeset ds=$1
79	typeset val=$2
80	typeset eroot=$(get_prop encryptionroot $ds)
81
82	if [[ "$eroot" != "$val" ]]; then
83		log_note "Expected encryption root '$val', got '$eroot'"
84		return 1
85	fi
86
87	return 0
88}
89
90function verify_origin
91{
92	typeset ds=$1
93	typeset val=$2
94	typeset orig=$(get_prop origin $ds)
95
96	if [[ "$orig" != "$val" ]]; then
97		log_note "Expected origin '$val', got '$orig'"
98		return 1
99	fi
100
101	return 0
102}
103