github.com/keybase/client/go@v0.0.0-20240309051027-028f7c731f8b/libkb/kbpackets.go (about) 1 // Copyright 2018 Keybase, Inc. All rights reserved. Use of 2 // this source code is governed by the included BSD license. 3 4 package libkb 5 6 import ( 7 "encoding/base64" 8 9 "github.com/keybase/client/go/kbcrypto" 10 ) 11 12 func 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 21 func 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 29 func 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 38 func 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 }