Uploaded image for project: 'Erlang/OTP'
  1. Erlang/OTP
  2. ERL-1257

Types of crypto.erl

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Trivial
    • Resolution: Fixed
    • Affects Version/s: OTP-23.0
    • Fix Version/s: OTP-23.1
    • Component/s: crypto
    • Labels:
      None

      Description

      Some spec declarations in the crypto module show serious confusion. For example, the code of "The New API" reads as follows:

      -spec crypto_init(Cipher, Key, FlagOrOptions) -> State | descriptive_error()
                                                         when Cipher :: cipher_no_iv(),
                                                              Key :: iodata(),
                                                              FlagOrOptions :: crypto_opts() | boolean(),
                                                              State :: crypto_state() .
      crypto_init(Cipher, Key, FlagOrOptions) ->
          crypto_init(Cipher, Key, <<>>, FlagOrOptions).
      
      
      -spec crypto_init(Cipher, Key, IV, FlagOrOptions) -> State | descriptive_error()
                                                             when Cipher :: cipher_iv(),
       ...
      

      [Apologies for the ugly format, but it's the one used in the file.]

      It cannot possibly be that Cipher is declared as cipher_no_iv() in the first function which then calls the second function which expects a cipher_iv() where these two types have nothing in common.

      The same problem exists in the specs of crypto_one_time.

      Also, in various places in the specs, FlagOrOptions reads crypto_opts() | boolean(), i.e., as above, but then again the code defines:

      -type crypto_opts() :: boolean() 
                           | [ crypto_opt() ] .
      

      Obviously, boolean() should appear in either the type declaration or in the |, not in both.

      Finally, I recommend taking out | descriptive_error() (an alias for no_return()) from the return type of these functions. They will never really return this.

        Attachments

          Activity

            People

            Assignee:
            hans Hans Nilsson
            Reporter:
            kostis kostis
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: