1// Copyright 2018 Keybase, Inc. All rights reserved. Use of
2// this source code is governed by the included BSD license.
3
4package libkb
5
6import (
7	"encoding/base64"
8
9	"github.com/keybase/client/go/kbcrypto"
10)
11
12func DecodeSKBPacket(data []byte) (*SKB, error) {
13	var info SKB
14	err := kbcrypto.DecodePacketFromBytes(data, &info)
15	if err != nil {
16		return nil, err
17	}
18	return &info, nil
19}
20
21func DecodeArmoredSKBPacket(s string) (*SKB, error) {
22	b, err := base64.StdEncoding.DecodeString(s)
23	if err != nil {
24		return nil, err
25	}
26	return DecodeSKBPacket(b)
27}
28
29func DecodeNaclEncryptionInfoPacket(data []byte) (NaclEncryptionInfo, error) {
30	var info NaclEncryptionInfo
31	err := kbcrypto.DecodePacketFromBytes(data, &info)
32	if err != nil {
33		return NaclEncryptionInfo{}, err
34	}
35	return info, nil
36}
37
38func DecodeArmoredNaclEncryptionInfoPacket(s string) (NaclEncryptionInfo, error) {
39	b, err := base64.StdEncoding.DecodeString(s)
40	if err != nil {
41		return NaclEncryptionInfo{}, err
42	}
43	return DecodeNaclEncryptionInfoPacket(b)
44}
45