<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://www.w3.org/Bugs/Public/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4"
          urlbase="https://www.w3.org/Bugs/Public/"
          
          maintainer="sysbot+bugzilla@w3.org"
>

    <bug>
          <bug_id>25388</bug_id>
          
          <creation_ts>2014-04-18 08:10:04 +0000</creation_ts>
          <short_desc>Boolean arguments</short_desc>
          <delta_ts>2014-05-12 05:58:12 +0000</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>Web Cryptography</product>
          <component>Web Cryptography API Document</component>
          <version>unspecified</version>
          <rep_platform>PC</rep_platform>
          <op_sys>All</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>WONTFIX</resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>P2</priority>
          <bug_severity>normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Anne">annevk</reporter>
          <assigned_to name="Ryan Sleevi">sleevi</assigned_to>
          <cc>d</cc>
    
    <cc>public-webcrypto</cc>
    
    <cc>watsonm</cc>
          
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>104073</commentid>
    <comment_count>0</comment_count>
    <who name="Anne">annevk</who>
    <bug_when>2014-04-18 08:10:04 +0000</bug_when>
    <thetext>Boolean arguments for methods are bad news. E.g. nobody ever remembers how addEventListener&apos;s third or XMLHttpRequest.prototype.open&apos;s third argument functions.

See http://c2.com/cgi/wiki?CodeSmellMetrics

It seems most of these methods could be designed to take a dictionary of sorts instead so the argument can be named and understood.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>104636</commentid>
    <comment_count>1</comment_count>
    <who name="Ryan Sleevi">sleevi</who>
    <bug_when>2014-04-29 00:09:22 +0000</bug_when>
    <thetext>(In reply to Anne from comment #0)
&gt; Boolean arguments for methods are bad news. E.g. nobody ever remembers how
&gt; addEventListener&apos;s third or XMLHttpRequest.prototype.open&apos;s third argument
&gt; functions.
&gt; 
&gt; See http://c2.com/cgi/wiki?CodeSmellMetrics
&gt; 
&gt; It seems most of these methods could be designed to take a dictionary of
&gt; sorts instead so the argument can be named and understood.

I can appreciate this feedback, however, it does not seem to be terribly useful nor correct from a usability perspective.

Please note that the core API objects already take a dictionary of arguments - the Algorithm dictionary (and it&apos;s sub-classes). This constitutes the bulk of the parameters one might specify to a given operation.

Unless you&apos;re suggesting a dictionary-of-dictionaries, which itself seems a code-smell, I&apos;m not sure how you see this being an improvement.

In all of these methods, there is only a single boolean parameter - and it has the exact same meaning across all methods - &quot;extractable&quot;.

Possible interpretations of what you see as a &quot;better&quot; API include:

dictionary DeriveKeyParams {
  AlgorithmIdentifier algorithm;  // Really, &quot;object&quot;
  Key key;
  AlgorithmIdentifier derivedKeyType;  // Really, &quot;object&quot;
  boolean extractable;
  Sequence&lt;KeyUsage&gt; keyUsages;  // Instead of array
};

Promise&lt;any&gt; deriveKey(DeriveKeyParams params);

And it makes the calling convention go from
window.crypto.subtle.deriveKey({ alg }, key, { derived alg }, false, [ &quot;encrypt&quot; ]);

to
window.crypto.subtle.deriveKey({ algorithm: { alg }, key: key, derivedKeyType: { derived alg }, extractable: false, keyUsages: [ &quot;encrypt&quot; ]);

I cannot see how that&apos;s a better syntax - in part, it forgoes any possibility of conciseness, because all the dictionary attributes cannot be minified or elided.

While I can understand holy wars have been raged over positional versus named arguments, that particular criticism doesn&apos;t seem to apply here, unless I&apos;m missing something fundamental that has changed in how Web APIs are written.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>104649</commentid>
    <comment_count>2</comment_count>
    <who name="Mark Watson">watsonm</who>
    <bug_when>2014-04-29 00:46:07 +0000</bug_when>
    <thetext>I interpreted the suggestion as being just to replace the extractable boolean with an enum { &quot;extractable&quot;, &quot;nonextractable&quot; }.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>104674</commentid>
    <comment_count>3</comment_count>
    <who name="Anne">annevk</who>
    <bug_when>2014-04-29 10:12:36 +0000</bug_when>
    <thetext>I would not suggest to nest objects, that does indeed seem bad. Can it be a keyUsages parameter with values as per Mark&apos;s suggestion?

The main problem is that if you look at a call such as

window.crypto.subtle.deriveKey({ alg }, key, { derived alg }, false, [ &quot;encrypt&quot; ]);

it is not clear what is going on. The same with the last argument being a length of sorts. 

I would need a much better understanding of the problem space to give more informed feedback as to what a better API would be. :-(</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>104712</commentid>
    <comment_count>4</comment_count>
    <who name="Ryan Sleevi">sleevi</who>
    <bug_when>2014-04-29 21:00:37 +0000</bug_when>
    <thetext>(In reply to Anne from comment #3)
&gt; I would not suggest to nest objects, that does indeed seem bad. Can it be a
&gt; keyUsages parameter with values as per Mark&apos;s suggestion?
&gt; 
&gt; The main problem is that if you look at a call such as
&gt; 
&gt; window.crypto.subtle.deriveKey({ alg }, key, { derived alg }, false, [
&gt; &quot;encrypt&quot; ]);
&gt; 
&gt; it is not clear what is going on. The same with the last argument being a
&gt; length of sorts. 

A length? Not sure I follow.

&gt; 
&gt; I would need a much better understanding of the problem space to give more
&gt; informed feedback as to what a better API would be. :-(

I didn&apos;t take Mark&apos;s comment as suggesting it was a KeyUsage, but in fact a new enumeration. That is

window.crypto.subtle.deriveKey({ alg }, key, {derived alg}, &quot;extractable&quot;, [ &quot;encrypt &quot; ]);

I took your reply as understanding it as

window.crypto.subtle.deriveKey({alg}, key, {derived alg}, [&quot;extractable&quot;, &quot;encrypt&quot;]);

The issue here is that &quot;extractable&quot;, as a key usage, doesn&apos;t have a 1:1 mapping to a given operation - that is &quot;extractability&quot; ties to both exportKey and wrapKey. Calling it &quot;exportKey&quot; doesn&apos;t conceptually fit, since you can extract a key via wrapping. Calling it &quot;wrapKey&quot; is off the table, since &quot;wrapKey&quot; is already a usage (indicating the given key can be used to wrap key, not that it is itself wrappable)

As a style design, I can certainly understand why boolean positional arguments are bad when used in abundance - eg: foo(true, false, true); However, it seems a bit dogmatic to suggest that any boolean arguments are bad.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>104714</commentid>
    <comment_count>5</comment_count>
    <who name="Domenic Denicola">d</who>
    <bug_when>2014-04-29 21:04:37 +0000</bug_when>
    <thetext>Are there any downsides to changing it from { true, false } to { &quot;extractable&quot;, &quot;nonextractable&quot; }? There seems to be at least a slighty readability upside.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>104716</commentid>
    <comment_count>6</comment_count>
    <who name="Domenic Denicola">d</who>
    <bug_when>2014-04-29 21:06:50 +0000</bug_when>
    <thetext>I guess the downside would be that, for objects in the spec with the `.extractable` property, you then would either:

- Have them return true/false, making them inconsistent with the methods under question
- Have them return &quot;extractable&quot;/&quot;nonextractable&quot;, which seems very error prone especially since both are truthy (e.g. `if (o.extractable) { ... }` will always pass).

With this in mind I think the boolean argument, while not very good for readability, is probably the best option.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>105677</commentid>
    <comment_count>7</comment_count>
    <who name="Ryan Sleevi">sleevi</who>
    <bug_when>2014-05-12 05:58:12 +0000</bug_when>
    <thetext>Closing, per Comment 6</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>