github.com/keybase/client/go@v0.0.0-20240309051027-028f7c731f8b/protocol/keybase1/device.go (about)

     1  // Auto-generated to Go types and interfaces using avdl-compiler v1.4.10 (https://github.com/keybase/node-avdl-compiler)
     2  //   Input file: avdl/keybase1/device.avdl
     3  
     4  package keybase1
     5  
     6  import (
     7  	"github.com/keybase/go-framed-msgpack-rpc/rpc"
     8  	context "golang.org/x/net/context"
     9  	"time"
    10  )
    11  
    12  type DeviceDetail struct {
    13  	Device          Device  `codec:"device" json:"device"`
    14  	Eldest          bool    `codec:"eldest" json:"eldest"`
    15  	Provisioner     *Device `codec:"provisioner,omitempty" json:"provisioner,omitempty"`
    16  	ProvisionedAt   *Time   `codec:"provisionedAt,omitempty" json:"provisionedAt,omitempty"`
    17  	RevokedAt       *Time   `codec:"revokedAt,omitempty" json:"revokedAt,omitempty"`
    18  	RevokedBy       KID     `codec:"revokedBy" json:"revokedBy"`
    19  	RevokedByDevice *Device `codec:"revokedByDevice,omitempty" json:"revokedByDevice,omitempty"`
    20  	CurrentDevice   bool    `codec:"currentDevice" json:"currentDevice"`
    21  }
    22  
    23  func (o DeviceDetail) DeepCopy() DeviceDetail {
    24  	return DeviceDetail{
    25  		Device: o.Device.DeepCopy(),
    26  		Eldest: o.Eldest,
    27  		Provisioner: (func(x *Device) *Device {
    28  			if x == nil {
    29  				return nil
    30  			}
    31  			tmp := (*x).DeepCopy()
    32  			return &tmp
    33  		})(o.Provisioner),
    34  		ProvisionedAt: (func(x *Time) *Time {
    35  			if x == nil {
    36  				return nil
    37  			}
    38  			tmp := (*x).DeepCopy()
    39  			return &tmp
    40  		})(o.ProvisionedAt),
    41  		RevokedAt: (func(x *Time) *Time {
    42  			if x == nil {
    43  				return nil
    44  			}
    45  			tmp := (*x).DeepCopy()
    46  			return &tmp
    47  		})(o.RevokedAt),
    48  		RevokedBy: o.RevokedBy.DeepCopy(),
    49  		RevokedByDevice: (func(x *Device) *Device {
    50  			if x == nil {
    51  				return nil
    52  			}
    53  			tmp := (*x).DeepCopy()
    54  			return &tmp
    55  		})(o.RevokedByDevice),
    56  		CurrentDevice: o.CurrentDevice,
    57  	}
    58  }
    59  
    60  type DeviceListArg struct {
    61  	SessionID int `codec:"sessionID" json:"sessionID"`
    62  }
    63  
    64  type DeviceHistoryListArg struct {
    65  	SessionID int `codec:"sessionID" json:"sessionID"`
    66  }
    67  
    68  type DeviceAddArg struct {
    69  	SessionID int `codec:"sessionID" json:"sessionID"`
    70  }
    71  
    72  type CheckDeviceNameFormatArg struct {
    73  	SessionID int    `codec:"sessionID" json:"sessionID"`
    74  	Name      string `codec:"name" json:"name"`
    75  }
    76  
    77  type DismissDeviceChangeNotificationsArg struct {
    78  }
    79  
    80  type CheckDeviceNameForUserArg struct {
    81  	SessionID  int    `codec:"sessionID" json:"sessionID"`
    82  	Username   string `codec:"username" json:"username"`
    83  	Devicename string `codec:"devicename" json:"devicename"`
    84  }
    85  
    86  type DeviceInterface interface {
    87  	// List devices for the user.
    88  	DeviceList(context.Context, int) ([]Device, error)
    89  	// List all devices with detailed history and status information.
    90  	DeviceHistoryList(context.Context, int) ([]DeviceDetail, error)
    91  	// Starts the process of adding a new device using an existing
    92  	// device.  It is called on the existing device.
    93  	// This is for kex2.
    94  	DeviceAdd(context.Context, int) error
    95  	// Checks the device name format.
    96  	CheckDeviceNameFormat(context.Context, CheckDeviceNameFormatArg) (bool, error)
    97  	// Dismisses the notifications for a new or revoked device
    98  	// assuming this is not that device.
    99  	DismissDeviceChangeNotifications(context.Context) error
   100  	// Checks a given device against all of user's past devices,
   101  	// including those that predate a reset. It will also check a device name
   102  	// for proper formatting. Return null error on success, and a non-null
   103  	// error otherwise.
   104  	CheckDeviceNameForUser(context.Context, CheckDeviceNameForUserArg) error
   105  }
   106  
   107  func DeviceProtocol(i DeviceInterface) rpc.Protocol {
   108  	return rpc.Protocol{
   109  		Name: "keybase.1.device",
   110  		Methods: map[string]rpc.ServeHandlerDescription{
   111  			"deviceList": {
   112  				MakeArg: func() interface{} {
   113  					var ret [1]DeviceListArg
   114  					return &ret
   115  				},
   116  				Handler: func(ctx context.Context, args interface{}) (ret interface{}, err error) {
   117  					typedArgs, ok := args.(*[1]DeviceListArg)
   118  					if !ok {
   119  						err = rpc.NewTypeError((*[1]DeviceListArg)(nil), args)
   120  						return
   121  					}
   122  					ret, err = i.DeviceList(ctx, typedArgs[0].SessionID)
   123  					return
   124  				},
   125  			},
   126  			"deviceHistoryList": {
   127  				MakeArg: func() interface{} {
   128  					var ret [1]DeviceHistoryListArg
   129  					return &ret
   130  				},
   131  				Handler: func(ctx context.Context, args interface{}) (ret interface{}, err error) {
   132  					typedArgs, ok := args.(*[1]DeviceHistoryListArg)
   133  					if !ok {
   134  						err = rpc.NewTypeError((*[1]DeviceHistoryListArg)(nil), args)
   135  						return
   136  					}
   137  					ret, err = i.DeviceHistoryList(ctx, typedArgs[0].SessionID)
   138  					return
   139  				},
   140  			},
   141  			"deviceAdd": {
   142  				MakeArg: func() interface{} {
   143  					var ret [1]DeviceAddArg
   144  					return &ret
   145  				},
   146  				Handler: func(ctx context.Context, args interface{}) (ret interface{}, err error) {
   147  					typedArgs, ok := args.(*[1]DeviceAddArg)
   148  					if !ok {
   149  						err = rpc.NewTypeError((*[1]DeviceAddArg)(nil), args)
   150  						return
   151  					}
   152  					err = i.DeviceAdd(ctx, typedArgs[0].SessionID)
   153  					return
   154  				},
   155  			},
   156  			"checkDeviceNameFormat": {
   157  				MakeArg: func() interface{} {
   158  					var ret [1]CheckDeviceNameFormatArg
   159  					return &ret
   160  				},
   161  				Handler: func(ctx context.Context, args interface{}) (ret interface{}, err error) {
   162  					typedArgs, ok := args.(*[1]CheckDeviceNameFormatArg)
   163  					if !ok {
   164  						err = rpc.NewTypeError((*[1]CheckDeviceNameFormatArg)(nil), args)
   165  						return
   166  					}
   167  					ret, err = i.CheckDeviceNameFormat(ctx, typedArgs[0])
   168  					return
   169  				},
   170  			},
   171  			"dismissDeviceChangeNotifications": {
   172  				MakeArg: func() interface{} {
   173  					var ret [1]DismissDeviceChangeNotificationsArg
   174  					return &ret
   175  				},
   176  				Handler: func(ctx context.Context, args interface{}) (ret interface{}, err error) {
   177  					err = i.DismissDeviceChangeNotifications(ctx)
   178  					return
   179  				},
   180  			},
   181  			"checkDeviceNameForUser": {
   182  				MakeArg: func() interface{} {
   183  					var ret [1]CheckDeviceNameForUserArg
   184  					return &ret
   185  				},
   186  				Handler: func(ctx context.Context, args interface{}) (ret interface{}, err error) {
   187  					typedArgs, ok := args.(*[1]CheckDeviceNameForUserArg)
   188  					if !ok {
   189  						err = rpc.NewTypeError((*[1]CheckDeviceNameForUserArg)(nil), args)
   190  						return
   191  					}
   192  					err = i.CheckDeviceNameForUser(ctx, typedArgs[0])
   193  					return
   194  				},
   195  			},
   196  		},
   197  	}
   198  }
   199  
   200  type DeviceClient struct {
   201  	Cli rpc.GenericClient
   202  }
   203  
   204  // List devices for the user.
   205  func (c DeviceClient) DeviceList(ctx context.Context, sessionID int) (res []Device, err error) {
   206  	__arg := DeviceListArg{SessionID: sessionID}
   207  	err = c.Cli.Call(ctx, "keybase.1.device.deviceList", []interface{}{__arg}, &res, 0*time.Millisecond)
   208  	return
   209  }
   210  
   211  // List all devices with detailed history and status information.
   212  func (c DeviceClient) DeviceHistoryList(ctx context.Context, sessionID int) (res []DeviceDetail, err error) {
   213  	__arg := DeviceHistoryListArg{SessionID: sessionID}
   214  	err = c.Cli.Call(ctx, "keybase.1.device.deviceHistoryList", []interface{}{__arg}, &res, 0*time.Millisecond)
   215  	return
   216  }
   217  
   218  // Starts the process of adding a new device using an existing
   219  // device.  It is called on the existing device.
   220  // This is for kex2.
   221  func (c DeviceClient) DeviceAdd(ctx context.Context, sessionID int) (err error) {
   222  	__arg := DeviceAddArg{SessionID: sessionID}
   223  	err = c.Cli.Call(ctx, "keybase.1.device.deviceAdd", []interface{}{__arg}, nil, 0*time.Millisecond)
   224  	return
   225  }
   226  
   227  // Checks the device name format.
   228  func (c DeviceClient) CheckDeviceNameFormat(ctx context.Context, __arg CheckDeviceNameFormatArg) (res bool, err error) {
   229  	err = c.Cli.Call(ctx, "keybase.1.device.checkDeviceNameFormat", []interface{}{__arg}, &res, 0*time.Millisecond)
   230  	return
   231  }
   232  
   233  // Dismisses the notifications for a new or revoked device
   234  // assuming this is not that device.
   235  func (c DeviceClient) DismissDeviceChangeNotifications(ctx context.Context) (err error) {
   236  	err = c.Cli.Call(ctx, "keybase.1.device.dismissDeviceChangeNotifications", []interface{}{DismissDeviceChangeNotificationsArg{}}, nil, 0*time.Millisecond)
   237  	return
   238  }
   239  
   240  // Checks a given device against all of user's past devices,
   241  // including those that predate a reset. It will also check a device name
   242  // for proper formatting. Return null error on success, and a non-null
   243  // error otherwise.
   244  func (c DeviceClient) CheckDeviceNameForUser(ctx context.Context, __arg CheckDeviceNameForUserArg) (err error) {
   245  	err = c.Cli.Call(ctx, "keybase.1.device.checkDeviceNameForUser", []interface{}{__arg}, nil, 0*time.Millisecond)
   246  	return
   247  }